如何在python中使用Recognite_sphinx API提高语音到文本转换的准确性

如何在python中使用Recognite_sphinx API提高语音到文本转换的准确性,python,speech-recognition,speech-to-text,cmusphinx,google-speech-api,Python,Speech Recognition,Speech To Text,Cmusphinx,Google Speech Api,您能否帮助我们使用python中的recognize\u sphinxAPI提高语音到文本转换的准确性 请找到下面的代码,这需要提高准确性的基础 import speech_recognition as sr #obtain path to "english.wav" in the same folder as this script from os import path AUDIO_FILE = path.join(path.dirname(path.realpath(file)),

您能否帮助我们使用python中的
recognize\u sphinx
API提高语音到文本转换的准确性

请找到下面的代码,这需要提高准确性的基础

import speech_recognition as sr    
#obtain path to "english.wav" in the same folder as this script
from os import path
AUDIO_FILE = path.join(path.dirname(path.realpath(file)), "english.wav")
AUDIO_FILE = path.join(path.dirname(path.realpath(file)), "french.aiff")
AUDIO_FILE = path.join(path.dirname(path.realpath(file)), "chinese.flac")
#use the audio file as the audio source
r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
audio = r.record(source) # read the entire audio file
#recognize speech using Sphinx
try:
print("Sphinx thinks you said " + r.recognize_sphinx(audio))
except sr.UnknownValueError:
print("Sphinx could not understand audio")
except sr.RequestError as e:
print("Sphinx error; {0}".format(e))

提前谢谢

我在研究我的智能私人助理有一段时间了,偶然发现了你的问题。我会尽力帮助你

所以,如果我理解正确的话。根据用户或音频文件所说的内容,您很难获得正确的输出?例如,音频/用户会说“你好!”输出将是“完全不同的东西”,对吗

回顾你的代码,我注意到你使用了3种不同的音频文件。每个文件都使用不同的语言。当您打开SpeechRecognition文档时,您将看到一个。在这个图书馆的参考资料中将有。首先要突出的是:

默认情况下,SpeechRecognition的Sphinx功能仅支持美式英语。还提供了其他语言包,但由于文件太大而未包括在内

我想你已经安装了所有需要的软件包。我不打算解释这一部分,因为这是不言自明的。无论如何,文档也解释了您可以

安装后,您只需使用Recognitor_instance.Recognite_sphinx的语言参数指定语言即可。例如,法语将指定为“fr-fr”,普通话将指定为“zh-CN”

不确定上面的代码是您的还是您只是从中复制粘贴。无论如何,你的代码有一些问题。您一直在用另一个文件覆盖AUDIO_FILE变量。因此,您获得的路径不是“chinese.flac”,而是“chinese.flac”

现在我想你们已经知道“语音到文本的准确性”可能有什么问题了。它是“听”中文,并试图将其输出为英语单词。这是不言自明的

要解决此问题,只需添加一个语言参数,并将其设置为您希望指定的语言。例如

import speech_recognition as sr

# obtain path to "chinese.flac" in the same folder as this script
from os import path

# AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "english.wav")
# AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "french.aiff")
AUDIO_FILE = path.join(path.dirname(path.realpath(__file__)), "chinese.flac")

# use the audio file as the audio source
r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
    audio = r.record(source)  # read the entire audio file

# recognize speech using Sphinx
try:
    # Just pass a language parameter
    print("Sphinx thinks you said " + r.recognize_sphinx(audio, language="zh-CN"))
except sr.UnknownValueError:
    print("Sphinx could not understand audio")
except sr.RequestError as e:
    print("Sphinx error; {0}".format(e))
希望这将有意义,并帮助你进一步