Python语音识别错误转换mp3文件

2024-05-08 19:37:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我第一次尝试用音频发短信。

import speech_recognition as sr
r = sr.Recognizer()
with sr.AudioFile("/path/to/.mp3") as source:
     audio = r.record(source)

当我执行上述代码时,会发生以下错误

<ipython-input-10-72e982ecb706> in <module>()
----> 1 with sr.AudioFile("/home/yogaraj/Documents/Python workouts/Python audio to text/show_me_the_meaning.mp3") as source:
      2     audio = sr.record(source)
      3 

/usr/lib/python2.7/site-packages/speech_recognition/__init__.pyc in __enter__(self)
    197                 aiff_file = io.BytesIO(aiff_data)
    198                 try:
--> 199                     self.audio_reader = aifc.open(aiff_file, "rb")
    200                 except aifc.Error:
    201                     assert False, "Audio file could not be read as WAV, AIFF, or FLAC; check if file is corrupted"

/usr/lib64/python2.7/aifc.pyc in open(f, mode)
    950             mode = 'rb'
    951     if mode in ('r', 'rb'):
--> 952         return Aifc_read(f)
    953     elif mode in ('w', 'wb'):
    954         return Aifc_write(f)

/usr/lib64/python2.7/aifc.pyc in __init__(self, f)
    345             f = __builtin__.open(f, 'rb')
    346         # else, assume it is an open file object already
--> 347         self.initfp(f)
    348 
    349     #

/usr/lib64/python2.7/aifc.pyc in initfp(self, file)
    296         self._soundpos = 0
    297         self._file = file
--> 298         chunk = Chunk(file)
    299         if chunk.getname() != 'FORM':
    300             raise Error, 'file does not start with FORM id'

/usr/lib64/python2.7/chunk.py in __init__(self, file, align, bigendian, inclheader)
     61         self.chunkname = file.read(4)
     62         if len(self.chunkname) < 4:
---> 63             raise EOFError
     64         try:
     65             self.chunksize = struct.unpack(strflag+'L', file.read(4))[0]

我不知道我做错了什么。有人能告诉我以上代码中的错误吗?


Tags: inselfsourcereadifusrasopen