读取使用 gTTS 生成的 wav 文件时出现问题
在我的项目中,我尝试使用 gTTS 从字符串生成音频文件,然后操作所述音频,但是当我尝试使用某些库(scipy 和 librosa)打开它时,它说格式无效。我做错了什么?提前致谢
代码:
tts = gTTS('Semáforo Gran Vía a 100 metros', lang='es')
filename = 'Senal.mp3'
tts.save(filename)
#y, sr = librosa.load('Senal.mp3')
x = wavfile.read(filename)
错误: 西皮
文件“C:/Users/Samuel/PycharmProjects/pythonProject/main.py”,第 108 行,位于 转换()
文件“C:/Users/Samuel/PycharmProjects/pythonProject/main.py”,第 25 行,转换中 x = wavfile.read(文件名)
文件“C:\Users\Samuel\PycharmProjects\pythonProject\venv\lib\site-packages\scipy\io\wavfile.py”,第 650 行,读取 file_size, is_big_endian = _read_riff_chunk(fid)
文件“C:\Users\Samuel\PycharmProjects\pythonProject\venv\lib\site-packages\scipy\io\wavfile.py”,第 521 行,在 _read_riff_chunk 中 raise ValueError(f"文件格式 {repr(str1)} 不理解。仅" ValueError:无法理解文件格式 b'\xff\xf3D\xc4'。仅支持“RIFF”和“RIFX”。
利布罗萨
文件“C:/Users/Samuel/PycharmProjects/pythonProject/main.py”,第 103 行,位于 转换()
文件“C:/Users/Samuel/PycharmProjects/pythonProject/main.py”,第 19 行,转换中 y, sr = librosa.load('Senal.mp3')
文件“C:\Users\Samuel\PycharmProjects\pythonProject\venv\lib\site-packages\librosa\util\decorators.py”,第 88 行,inner_f 返回 f(*args, **kwargs)
文件“C:\Users\Samuel\PycharmProjects\pythonProject\venv\lib\site-packages\librosa\core\audio.py”,第 174 行,加载中 y, sr_native = __audioread_load(路径, 偏移量, 持续时间, dtype)
文件“C:\Users\Samuel\PycharmProjects\pythonProject\venv\lib\site-packages\librosa\core\audio.py”,第 198 行,在 __audioread_load 中 以 audioread.audio_open(path) 作为 input_file:
文件“C:\Users\Samuel\PycharmProjects\pythonProject\venv\lib\site-packages\audioread_init_.py”,第 116 行,位于 audio_open 中 引发 NoBackendError() audioread.exceptions.NoBackendError
进程已完成,退出代码为 1
For my project I tried to use gTTS to generate an audio file from a String and then manipulate said audio, but when I tried to open it with some libraries (scipy and librosa), it says that the format is invalid. What am I doing wrong? Thanks in advance
The code:
tts = gTTS('Semáforo Gran Vía a 100 metros', lang='es')
filename = 'Senal.mp3'
tts.save(filename)
#y, sr = librosa.load('Senal.mp3')
x = wavfile.read(filename)
The error(s):
Scipy
File "C:/Users/Samuel/PycharmProjects/pythonProject/main.py", line 108, in
conversion()
File "C:/Users/Samuel/PycharmProjects/pythonProject/main.py", line 25, in conversion
x = wavfile.read(filename)
File "C:\Users\Samuel\PycharmProjects\pythonProject\venv\lib\site-packages\scipy\io\wavfile.py", line 650, in read
file_size, is_big_endian = _read_riff_chunk(fid)
File "C:\Users\Samuel\PycharmProjects\pythonProject\venv\lib\site-packages\scipy\io\wavfile.py", line 521, in _read_riff_chunk
raise ValueError(f"File format {repr(str1)} not understood. Only "
ValueError: File format b'\xff\xf3D\xc4' not understood. Only 'RIFF' and 'RIFX' supported.
Librosa
File "C:/Users/Samuel/PycharmProjects/pythonProject/main.py", line 103, in
conversion()
File "C:/Users/Samuel/PycharmProjects/pythonProject/main.py", line 19, in conversion
y, sr = librosa.load('Senal.mp3')
File "C:\Users\Samuel\PycharmProjects\pythonProject\venv\lib\site-packages\librosa\util\decorators.py", line 88, in inner_f
return f(*args, **kwargs)
File "C:\Users\Samuel\PycharmProjects\pythonProject\venv\lib\site-packages\librosa\core\audio.py", line 174, in load
y, sr_native = __audioread_load(path, offset, duration, dtype)
File "C:\Users\Samuel\PycharmProjects\pythonProject\venv\lib\site-packages\librosa\core\audio.py", line 198, in __audioread_load
with audioread.audio_open(path) as input_file:
File "C:\Users\Samuel\PycharmProjects\pythonProject\venv\lib\site-packages\audioread_init_.py", line 116, in audio_open
raise NoBackendError()
audioread.exceptions.NoBackendError
Process finished with exit code 1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
似乎对我来说很好。
Python = 3.10.8,GTTS = 2.3.0和Librosa 0.9.2输出
It seems to work fine for me With Python=3.10.8, gTTS=2.3.0, and librosa 0.9.2
Output: