Deepspeech - 推断更多音频文件并保存输出

Deepspeech - inferring for more audio files and saving the output

我已经完成了对来自 Mozilla 的 deepspeech 通用语音数据的培训,现在我能够获得单个音频 .wav 文件的输出。下面是我正在使用的命令。

(deepspeech-venv) megha@megha-medion:~/Alu_Meg/DeepSpeech_Alug_Meg/DeepSpeech$ ./deepspeech my_exportdir/model.pb/output_graph.pb models/alphabet.txt myAudio_for_testing.wav

这里,myAudio_for_testing.wav 是我用来获取以下输出的音频文件。

TensorFlow: v1.6.0-9-g236f83e
DeepSpeech: v0.1.1-44-gd68fde8
Warning: reading entire model file into memory. Transform model file into an mmapped graph to reduce heap usage.
2018-06-29 14:51:35.832686: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
heritor teay we decide the lunch ha annral limined eddition of y ye com im standmat

继承人我们决定午餐 ha annral limited edition of y ye com im standmat

这是我的几个问题,

1) 上面加粗的句子是我音频的输出。我怎样才能保存这个文件?

2) 我有大约 2000 个这样的音频文件。如何逐一读取并获得输出?我试图在 python 中编写一个脚本来读取我拥有的所有 .wav 音频文件,但是由于我的 deepspeech 使用了一些保存在虚拟环境中的资源,所以我不知道如何编写我的 deepspeech脚本中的命令。 你们能给我一些提示吗?会有很大的帮助。

谢谢:)

梅格哈

我找到了第一个问题的解决方案。我们可以将输出重定向到某个文件,如下所示。

(deepspeech-venv) megha@megha-medion:~/Alu_Meg/DeepSpeech_Alug_Meg/DeepSpeech$ ./deepspeech my_exportdir/model.pb/output_graph.pb models/alphabet.txt myAudio_for_testing.wav > output_test.csv
TensorFlow: v1.6.0-9-g236f83e
DeepSpeech: v0.1.1-44-gd68fde8
Warning: reading entire model file into memory. Transform model file into an mmapped graph to reduce heap usage.
2018-06-29 15:22:50.275833: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA

我刚刚在命令后添加了 > output_test.csv

但是第二个问题我还是想不通。

对于第二个问题,我在 Deepspeech 的 client.py 文件中添加了一个额外的部分来遇到一些文件,并将每个成绩单保存在一个 excel 文件中,并以相应的文件名作为索引价值。

> r =csv.reader(open('my_CSV_file.csv')) lines = list(r) pathToAudio =
> args.audio#sys.argv[3] audio_files = os.listdir(pathToAudio) for i in
> range(1,len(lines)):
>     for eachfile in audio_files :
>         if eachfile.endswith(".wav"):  
>             if(eachfile == lines[i][1]):
>               file_Path = pathToAudio + "/" + eachfile 
>                   print("File to be read is ",  file_Path)
>                   fs, audio = wav.read(file_Path)
>                   audio_length = len(audio) * ( 1 / 16000)
>                   assert fs == 16000, "Only 16000Hz input WAV files are supported for now!"
>                   print('Running inference.', file=sys.stderr)
>                   inference_start = timer()
>                   output = ds.stt(audio, fs)
>                   lines[i][2] = output                   
>                   writer = csv.writer(open('my_CSV_file', 'w'))
>                   writer.writerows(lines)
>                   print(output)
>                   inference_end = timer() - inference_start
>                   print('Inference took %0.3fs for %0.3fs audio file.' % (inference_end, audio_length), file=sys.stderr)

我不知道现在回答你的问题是否为时已晚,但我将我的回答留在此处以防其他人可能遇到 same/similar 问题。

在 Mozilla/DeepSpeech github 页面上,他们共享了一个名为 transcribe.py 的脚本。在这个脚本中,他们有一个名为 transcribe_many(src_paths,dst_paths) 的函数。基本上,此函数接受音频文件位置列表 (src_paths) 的输入并将它们加载到 RAM,然后以 multi-processing 方式进行推理。输出被写入“dst_paths”的位置。

这是我在上面 link 共享的文件中的代码预览。

def transcribe_many(src_paths,dst_paths):
    pbar = create_progressbar(prefix='Transcribing files | ', max_value=len(src_paths)).start()
    for i in range(len(src_paths)):
        p = Process(target=transcribe_file, args=(src_paths[i], dst_paths[i]))
        p.start()
        p.join()
        log_progress('Transcribed file {} of {} from "{}" to "{}"'.format(i + 1, len(src_paths), src_paths[i], dst_paths[i]))
        pbar.update(i)
    pbar.finish()