我最近尝试学习如何转录音频文件,但我对python不是很熟悉。
我已阅读以下网站的SpeechRecognition中的示例
https://github.com/Uberi/speech_recognition/blob/master/examples/audio_transcribe.py
我尝试使用以下代码使用它们:
然而,看起来我无法在Windows计算机中导入我的文件。
我想知道我的计算机中是否有一个带有路径
的wav文件“C:\用户\陈\下载\ english.wav”
我试图在我的python代码中用“C:\ Users \ Chen \ Downloads”替换文件。
但它告诉我
FileNotFoundError:[Errno 2]没有这样的文件或目录:'C:\ Users \ Chen \ english.wav'
请帮我解决问题。
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")
# 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
print("Google Speech Recognition thinks you said " + r.recognize_google(audio))
答案 0 :(得分:0)
如果需要识别文本,请使用函数listen()
r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
audio = r.listen(source) # read the entire audio file
text = r.recognize_google(audio)
print("Google Speech Recognition thinks you said " + text)
答案 1 :(得分:0)
# Below code is for audio file in hindi
file = "hindi.wav"
with sr.AudioFile(file) as source:
audio = r.listen(source)
text = r.recognize_google(audio, language='hi-IN')
print("Text : " + text)