0

我正在尝试使用 Mozilla Deepspeech 转录(语音到文本),在 python 子进程中使用下面的代码来执行这个命令这个命令在终端中工作并且也在 python 子进程中执行并且没有错误,但是当 result.txt 生成时它是空白的。

#!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)

非常感谢任何帮助。谢谢

4

1 回答 1

0

您需要将每个空格分隔的字符串作为单独的字符串传递给子进程

替换这个:

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)

有了这个:

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=此外,您可以使用连同重定向错误stdout=

例如。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)

于 2021-11-07T09:07:04.967 回答