【发布时间】:2022-01-23 20:25:16
【问题描述】:
我正在使用 Speech_recognition 读取 .wav 文件,使用以下代码:
r = sr.Recognizer()
with sr.AudioFile(AUDIO_FILE) as source:
audio = r.record(source)
但是,我收到以下错误:file does not start with RIFF id
我尝试了以下解决方案并使用了以下代码,但最终出现了新错误:
Solution 1 代码:
import librosa
import soundfile as sf
x,_ = librosa.load('sample_wav.WAV', sr=16000)
错误:Error opening 'C:\\Users\\biswankar.das\\Downloads\\sample_wav.WAV': File contains data in an unknown format
Solution 2 代码:
from scipy.io import wavfile
samplerate, data = wavfile.read(file_path)
错误:File format b'\xff\xe3\x18\xc4' not understood. Only 'RIFF' and 'RIFX' supported.
我尝试在网上分析这个文件,格式是MPEG,以下是详细信息: 分析细节:
General
Format : MPEG Audio
File size : 246 KiB
Duration : 4 min 11 s
Overall bit rate mode : Constant
Overall bit rate : 8 000 b/s
FileExtension_Invalid : m1a mpa mpa1 mp1 m2a mpa2 mp2 mp3
Audio
Format : MPEG Audio
Format version : Version 2.5
Format profile : Layer 3
Duration : 4 min 11 s
Bit rate mode : Constant
Bit rate : 8 000 b/s
Channel(s) : 1 channel
Sampling rate : 8 000 Hz
Frame rate : 13.889 FPS (576 SPF)
Compression mode : Lossy
Stream size : 246 KiB (100%)
我也尝试使用 ffmpeg 以及使用以下代码,但在尝试相同时出现错误:
import pydub as pydub
from pydub import AudioSegment
AudioSegment.ffmpeg = "\\ffmpeg.exe"
pydub.AudioSegment.converter = r"\\ffmpeg.exe"
data = AudioSegment.from_wav("sample_wav.wav")
错误:The system cannot find the file specified - 尽管我可以读取相同的文件位置
【问题讨论】:
-
看这篇文章。它可能会有所帮助。 stackoverflow.com/questions/25672289/….
-
您的文件似乎命名错误。它似乎是一个
.mp3文件而不是.wav。您是否尝试过重命名它(我不确定 librosa/libsoundfile/audioread 是否注意文件扩展名,但它们可能并且最终可能会被混淆)。另请注意,librosa 对 MP3 的支持取决于audioread。见librosa docs。 This SO question 可能会有所帮助。
标签: python ffmpeg speech-recognition speech-to-text