我有一个视频文件,我想确定演讲者的置信度。为了执行此操作,我首先从视频文件中提取音频。下面是代码。
from moviepy.editor import *
local_video_path = "Video.mp4"
sound = AudioFileClip(local_video_path)
sound.write_audiofile("sound.wav", 44100, 2, 2000,"pcm_s32le")
以上代码成功运行并创建音频文件。
在下一步中,我将使用语音识别库来确定说话者的置信度。我正在使用以下代码
import speech_recognition as sr
recognizer = sr.Recognizer()
audio = sr.AudioFile('sound.wav')
#text = recognizer.recognize_audio(audio)
text = recognizer.recognize_google(audio)
confidence = recognizer.confidence()
print(confidence)
但我收到错误:
AssertionError: ``audio_data`` must be audio data
我什至尝试了不同的方法,例如来自 this URL 的以下代码。
import speech_recognition as sr
r = sr.Recognizer()
file = sr.AudioFile('sound.wav')
with file as source:
audio_file = r.record(source,duration=20)
print(r.recognize_google(audio_file))
但是上面的代码给出了 ValueError: Audio file Could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC;检查文件是否损坏或采用其他格式。
如何解决这个问题?