Python 读取 mp3 文件时出现问题

import speech_recognition as sr

print(sr.__version__)

r = sr.Recognizer()


file_audio = sr.AudioFile('damn1.mp3')


with file_audio as source:

   audio_text = r.record(source)


print(type(audio_text))

print(r.recognize_google(audio_text))

我运行这个程序时遇到问题。我得到的输出如下:


Traceback (most recent call last):

  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 203, in __enter__

    self.audio_reader = wave.open(self.filename_or_fileobject, "rb")

  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\wave.py", line 510, in open

    return Wave_read(f)

  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\wave.py", line 164, in __init__

    self.initfp(f)

  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\wave.py", line 131, in initfp

    raise Error('file does not start with RIFF id')

wave.Error: file does not start with RIFF id

在处理上述异常的过程中,又出现了一个异常:


Traceback (most recent call last):

  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\site-packages\speech_recognition\__init__.py", line 208, in __enter__

    self.audio_reader = aifc.open(self.filename_or_fileobject, "rb")

  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\aifc.py", line 917, in open

    return Aifc_read(f)

  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\aifc.py", line 352, in __init__

    self.initfp(file_object)

  File "C:\Users\kubar\AppData\Local\Programs\Python\Python38-32\lib\aifc.py", line 316, in initfp

    raise Error('file does not start with FORM id')

aifc.Error: file does not start with FORM id


缥缈止盈
浏览 158回答 1
1回答

青春有我

MP3 是一种压缩格式。操作音频时切勿使用它,因为大多数处理音频的工具都是在非压缩音频流上进行操作的。因此,即使此类工具接受您的文件,它也可能会首先对其进行转换,这会消耗时间和空间。此外,从事音频工作的专业人士(音乐家、工程师等)从不使用 MP3:避免将其与对您的工作具有一定重要性的音频材料一起使用(即使是存档,因为压缩是不可逆的),总是更喜欢使用非压缩格式作为 WAV 或 AIF 代替(这里库似乎期望 AIF)。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python