【发布时间】:2019-02-25 19:25:19
【问题描述】:
我最近尝试学习如何转录音频文件,但我对 python 不是很熟悉。
我已阅读以下网站的 SpeechRecognition 中的示例
https://github.com/Uberi/speech_recognition/blob/master/examples/audio_transcribe.py
我尝试使用以下代码来使用它们:
但是,我似乎无法在我的 Windows 计算机中导入我的文件。
我想知道我的计算机中是否有带有路径的 wav 文件
"C:\Users\Chen\Downloads\english.wav"
我尝试在我的 python 代码中将 file 替换为“C:\Users\Chen\Downloads”。
但它告诉我
FileNotFoundError: [Errno 2] No such file or directory: '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))
【问题讨论】:
-
试试
AUDIO_FILE = "C:\Users\Chen\Downloads\english.wav"。并尝试了解path.dirname的作用。你基本上用path.dirname剥离“下载”,这就是它找不到文件的原因。