[RESOLVED] soundfile.LibsndfileError: Error opening: File contains data in an unimplemented format.
vi-dev0 opened this issue · comments
Hello guys, 3 days trying to find solution
Use Google, StackOverflow, and issues in this repo
But nothing can help me
On windows, my code works but on Ubuntu doesn't work
soundfile.LibsndfileError: Error opening <_io.BytesIO object at 0x7fbc93697630>: File contains data in an unimplemented format.
import io
import librosa
import soundfile as sf
from aiogram import Bot, Dispatcher, types
from aiogram.utils import executor
import sqlite3
import config
bot = Bot(token=config.TGTOKEN)
dp = Dispatcher(bot)
@dp.message_handler(content_types=types.ContentType.VOICE)
async def process_voice_message(message: types.Message):
voice_file = io.BytesIO()
await message.voice.download(destination=voice_file)
y, sr = librosa.load(voice_file, sr=16000)
voice_file.close()
voice_file = io.BytesIO()
sf.write(voice_file, y, sr, format='WAV', subtype='PCM_16')
voice_file.seek(0)
text = recognize_speech(voice_file)
await message.reply(text)
record_stat(message.from_user.id)
def recognize_speech(file):
import speech_recognition as sr
r = sr.Recognizer()
with sr.AudioFile(file) as source:
audio = r.record(source)
try:
text = r.recognize_google(audio, language='ru-RU')
return text
except sr.UnknownValueError:
return "Не удалось распознать речь"
except sr.RequestError as e:
return f"Произошла ошибка при обращении к серверу распознавания речи: {e}"
Can someone help me?
Your libsndfile is probably outdated. pip install --upgrade soundfile
should set you up with a current version.
Requirement already up-to-date: soundfile in ./.local/lib/python3.8/site-packages (0.12.1)
Requirement already satisfied, skipping upgrade: cffi>=1.0 in ./.local/lib/python3.8/site-packages (from soundfile) (1.15.1)
Requirement already satisfied, skipping upgrade: pycparser in ./.local/lib/python3.8/site-packages (from cffi>=1.0->soundfile) (2.21)
I tried to update, reinstall via pip, uninstall and reinstall, checked all libraries for up-to-date, performed apt update && apt upgrade
several times and nothing helped
then check soundfile.__version__
and soundfile.__libsndfile_version__
0.12.1 soundfile.__version__
1.0.28 soundfile.__libsndfile_version__
That's the old libsndfile. Try pip install --force-reinstall soundfile
. I only recently added a wheel with a bundled libsndfile for older versions of Ubuntu, and you might still have the previous, non-bundled version.
Try upgrading your pip and wheel (pip install --upgrade pip wheel
), and then reinstalling soundfile again? It is still downloading the non-bundled wheel instead of the manylinux one.
Does pip
link to the correct pip? Try python -m pip install --force-reinstall soundfile
(using the same python
you use to execute your program).
Alternatively, just download the appropriate wheel from pypi by hand with your browser and pip install it directly. Then you can figure out your pip problems another time.
Does
pip
link to the correct pip? Trypython -m pip install --force-reinstall soundfile
(using the samepython
you use to execute your program).
Friend, you're just the best, the best. Thank you, it helped! I spent a lot of time agonizing over how to solve this problem! Thank you very much!
The solution has been found!
Glad it worked!
Does
pip
link to the correct pip? Trypython -m pip install --force-reinstall soundfile
(using the samepython
you use to execute your program).Friend, you're just the best, the best. Thank you, it helped! I spent a lot of time agonizing over how to solve this problem! Thank you very much! The solution has been found!
what's your soundfile version now? i can only see the 0.12.1 is the latest?
I am facing the same issue, I have installed the libsandfile==1.2.2. But I am getting print(sf.__libsndfile_version__)
== 1.2.0. I am using gcloud server.
apt-get update
apt-get install libsndfile1
apt-get install ffmpeg