python - 使用 speech_recognition Python 库进行语音到文本转换会出错
问题描述
我已经编写了一个 python 代码来将语音转换为文本,最终我想将输出保存在一个文件中。
import speech_recognition as sr
r= sr.Recognizer()
with sr.AudioFile("c://Akash//male.wav") as source:
audio= r.listen(source)
try:
print("system predicts"+r.recognize_google(audio))
except Exception:
print("something wrong")
上面的代码总是把我带到异常部分并打印“有问题”。我还需要帮助将输出保存到文本文件。编辑 1:错误
编辑 2:我通过使用 Azure Data Lake 中的音频文件进行了尝试,并且成功了一次。但在那之后它没有用。不知道为什么当我再次执行相同的代码时,它不起作用。
解决方案
我猜这个问题可能是由路径引起的"c://Akash//male.wav"
,可能是斜杠 - 如果您使用的是Windows
操作系统,请尝试更改它"c:/Akash/male.wav"
或"c:\\Akash\\male.wav"
. 如果两者都没有帮助,请用单行替换你的 4 行try
-except
print("system predicts"+r.recognize_google(audio))
并将错误信息中的内容写给我们。
编辑:它提出了UnknownValueError
,在我检查了speech_recognition
名为audio_transcribe.py的使用示例之后,我认为这只是意味着Google Speech Recognition could not understand audio
.
推荐阅读
- mysql - 我怎样才能加入4张桌子?
- expo - 使用 BottomTabNavigator 切换屏幕时反应导航屏幕跳跃
- maven - 从另一个 Maven 项目中调用 Maven
- python - 如何使用 Django 在服务器上存储一个大的、非常频繁访问的列表?
- sql - 从 MSSQL 到 Oracle 的连接查询
- powershell - 从 Invoke-AzVMRunCommand 将参数传递给 PowerShell 脚本
- google-cloud-platform - GCP 数据流:打印 PCollection 数据
- c# - 关于 Twilio 网络挂钩
- javascript - Azure Data Lake Gen2 PUT 授权
- powershell - IIS 应用程序请求路由缓存控制规则是否可编写脚本?