【问题标题】:Deepspeech - inferring for more audio files and saving the outputDeepspeech - 推断更多音频文件并保存输出
【发布时间】:2020-08-03 21:36:01
【问题描述】:

我已经完成了来自 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

heritor teay 我们决定午餐时间限制版 y ye com im standmat

这是我的几个问题,

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

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

谢谢:)

梅加

【问题讨论】:

    标签: python command-line output mozilla-deepspeech


    【解决方案1】:

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

    (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

    但我仍然无法弄清楚我的第二个问题。

    【讨论】:

      【解决方案2】:

      对于我的第二个问题,我在 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)
      

      【讨论】:

        【解决方案3】:

        我不知道现在回答您的问题是否为时已晚,但我将回答留在这里,以防其他人可能遇到相同/类似的问题。

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

        这是我在上面分享链接的文件中的代码预览。

        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()
        

        【讨论】:

          猜你喜欢
          • 2021-06-14
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-05-23
          • 2017-04-13
          • 1970-01-01
          • 1970-01-01
          • 2022-11-14
          相关资源
          最近更新 更多