【问题标题】:demo how to Transcribe an audio file using the SpeechRecognition演示如何使用 SpeechRecognition 转录音频文件
【发布时间】: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 剥离“下载”,这就是它找不到文件的原因。

标签: python speech-recognition


【解决方案1】:

如果需要识别文本,请使用函数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)

【讨论】:

    【解决方案2】:
    # 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)
    

    【讨论】:

    • 值得添加几句话来解释你在做什么以及问题是什么
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-17
    • 2018-02-26
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    相关资源
    最近更新 更多