使用WAV文件在python中发送文本

问题描述 投票:0回答:1

我尝试在WAV文件中转换语音,但我被困在这里。很多教程都给出了相同的代码,但它对我不起作用。这里是:

import speech_recognition as sr
r = sr.Recognizer()

with sr.AudioFile("hello_world.wav") as source:
    audio = r.record(source)
try:
    s = r.recognize_google(audio)
    print("Text: "+s)
except Exception as e:
    print("Exception: "+str(e))

“hello_world.wav”文件与代码位于同一个库中。我没有任何错误。控制台:

C:\Users\python.exe "D:/voice_recognition.py"
Exception:

Process finished with exit code 0

救命? :)

(对不起,如果我的英语不好)

python speech-recognition google-speech-api speech-recognition-api
1个回答
0
投票

好的,我确实让它成功了。如果有人遇到同样的问题,我会发布适合我的代码:

import speech_recognition as sr
r = sr.Recognizer()

hellow=sr.AudioFile('hello_world.wav')
with hellow as source:
    audio = r.record(source)
try:
    s = r.recognize_google(audio)
    print("Text: "+s)
except Exception as e:
    print("Exception: "+str(e))

也许是因为我使用'而不是'。

© www.soinside.com 2019 - 2024. All rights reserved.