0

I'm trying to transcribe (speech to text) using Mozilla Deepspeech, using below code in python subprocess to execute this command this command is working in terminal and also executing in python subprocess and there and no errors, but when result.txt is generated it is blank.

#!C:\Program Files\Python36\python.exe
print("Content-type: text/html\n")
import subprocess,os,sys

with open("C:/result.txt", mode="wb") as fd:
subprocess.run(["deepspeech", "--model", "C:/deepspeechwkdeepspeech-0.6.0-models/output_graph.pb --lm C:/deepspeech/deepspeech-0.6.0-models/lm.binary --trie C:/deepspeech/deepspeech-0.6.0-models/trie", "--audio", "C:/deepspeech/audio/8455-210777-0068.wav"], stdout=fd)

Any help is highly appreciated. Thanks

user3653474
  • 3,393
  • 6
  • 49
  • 135

1 Answers1

0

You need to pass each space separated string as individual string to subprocess

Replace this:

subprocess.run(["deepspeech", "--model", "C:/deepspeechwkdeepspeech-0.6.0-models/output_graph.pb --lm C:/deepspeech/deepspeech-0.6.0-models/lm.binary --trie C:/deepspeech/deepspeech-0.6.0-models/trie", "--audio", "C:/deepspeech/audio/8455-210777-0068.wav"], stdout=fd)

With this:

subprocess.run(["deepspeech", "--model", "C:/deepspeechwkdeepspeech-0.6.0-models/output_graph.pb", "--lm", "C:/deepspeech/deepspeech-0.6.0-models/lm.binary", "--trie", "C:/deepspeech/deepspeech-0.6.0-models/trie", "--audio", "C:/deepspeech/audio/8455-210777-0068.wav"], stdout=fd)

Also, you can redirect the error using stderr= along with stdout=

eg. subprocess.run(["deepspeech", "--model", "C:/deepspeechwkdeepspeech-0.6.0-models/output_graph.pb --lm C:/deepspeech/deepspeech-0.6.0-models/lm.binary --trie C:/deepspeech/deepspeech-0.6.0-models/trie", "--audio", "C:/deepspeech/audio/8455-210777-0068.wav"], stdout=fd, stderr=fd)

azro
  • 53,056
  • 7
  • 34
  • 70
  • Thanks for your answer, I tried this code `import subprocess,os,sys with open("C:/result.txt", mode="wb") as fd: subprocess.run(["deepspeech", "--model", "C:/deepspeechwkdeepspeech-0.6.0-models/output_graph.pb --lm C:/deepspeech/deepspeech-0.6.0-models/lm.binary --trie C:/deepspeech/deepspeech-0.6.0-models/trie", "--audio", "C:/deepspeech/audio/8455-210777-0068.wav"], stdout=fd, stderr=fd)` but getting blank file – user3653474 Nov 08 '21 at 04:05