使用语音识别将 Python 语音转为文本

标签 python python-3.x speech-recognition speech-to-text google-speech-api

我正在制作一个使用语音转文本的软件。我在 stackoverflow 上读过一些文章和帖子。我尝试了这段代码-

r = sr.Recognizer()
with sr.Microphone(device_index=1) as source:
    r.adjust_for_ambient_noise(source)
    print("Speak:")
    audio = r.listen(source)

try:
    print("You said " + r.recognize_google(audio)+';')
except sr.UnknownValueError:
    print("Could not understand audio")
except sr.RequestError as e:
    print("Could not request results; {0}".format(e))

在我运行代码后,当它到达这部分时,它会进入输入阶段并停止。它不执行任何操作,并且 tkinter window 不响应。看起来像这样。 enter image description here

我尝试了 r.recognize_googler.recognize_sphinx。我也尝试过不使用麦克风索引。我不明白发生了什么事。当谈到r.listen(source)时它就停止了。感谢您的建议。

最佳答案

你可以试试这个code在 GitHub 中。

关于使用语音识别将 Python 语音转为文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53112910/

相关文章:

Python从特定日期中提取周数

python - SQLALchemy 访问列对象

python-3.x - PYODBC + PYINSTALLER : EXE listing different drivers as compiler (PyCharm), 32 位 Access 和 64 位 Python

python - 属性(property)装饰师

c++ - 在 C++ 中将 Gstreamer 与 Google 语音 API(流式转录)结合使用

python - 如何使用join方法和sort方法

python - 如何在Python中的Google Cloud Function中运行子流程

javascript - 访问 extjs 动态创建的元素

Android语音识别权限不足(错误码9)

javax.sound.sampled.LineUnavailableException : line with format PCM_SIGNED 16000. 0 Hz,16 位,单声道,2 字节/帧