我正在尝试使用python将mp4文件转换为文本,但出现此错误

时间:2020-05-20 06:44:03

标签: python ffmpeg jupyter-notebook

我正在jupyter笔记本中执行此操作,并且视频被放置在mp4文件所在的同一文件夹中,我想通过识别视频中所说的内容将nanavi.mp4文件转换为文本,但是我遇到了这个错误

在此处输入代码

import speech_recognition as sr

import os

import pyaudio

command2mp3 = 'ffmpeg -i nanavi.mp4 nanavi.mp3'

command2wav = 'ffmpeg -i nanavi.mp3 nanavi.wav'

os.system(command2mp3)

os.system(command2wav)

r = sr.Recognizer()

with sr.AudioFile("nanavi.wav") as source:

    audio = r.record(source, duration=10)

    print(r.recognize_google(audio))

**ERROR**

该文件已经放置在ipynb文件的文件夹中

FileNotFoundError                         Traceback (most recent call last)

<ipython-input-19-9f97c7524cb8> in <module>

----> 1 with sr.AudioFile("nanavi.wav") as source:

      2     audio = r.record(source, duration=10)

      3     print(r.recognize_google(audio))


C:\ProgramData\anaconda3\lib\site-packages\speech_recognition\__init__.py in __enter__(self)

    201         try:
    202             # attempt to read the file as WAV
--> 203             self.audio_reader = wave.open(self.filename_or_fileobject, "rb")
    204             self.little_endian = True  # RIFF WAV is a little-endian format (most ``audioop`` operations assume that the frames are stored in little-endian form)
    205         except (wave.Error, EOFError):

C:\ProgramData\anaconda3\lib\wave.py in open(f, mode)
    508             mode = 'rb'
    509     if mode in ('r', 'rb'):
--> 510         return Wave_read(f)
    511     elif mode in ('w', 'wb'):
    512         return Wave_write(f)

C:\ProgramData\anaconda3\lib\wave.py in __init__(self, f)
    158         self._i_opened_the_file = None
    159         if isinstance(f, str):
--> 160             f = builtins.open(f, 'rb')
    161             self._i_opened_the_file = f
    162         # else, assume it is an open file object already

FileNotFoundError: [Errno 2] No such file or directory: 'nanavi.wav'

1 个答案:

答案 0 :(得分:0)

尝试通过运行命令来安装flac

pdf.Options.PageBreaksEnhancedAlgorithm = true;

这是一个与编解码器相关的常见问题,安装flac即可解决。