Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RESOLVED] soundfile.LibsndfileError: Error opening: File contains data in an unimplemented format. #380

Closed
vi-dev0 opened this issue Mar 31, 2023 · 15 comments

Comments

@vi-dev0
Copy link

vi-dev0 commented Mar 31, 2023

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?

@bastibe
Copy link
Owner

bastibe commented Apr 1, 2023

Your libsndfile is probably outdated. pip install --upgrade soundfile should set you up with a current version.

@vi-dev0
Copy link
Author

vi-dev0 commented Apr 1, 2023

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

@bastibe
Copy link
Owner

bastibe commented Apr 1, 2023

then check soundfile.__version__ and soundfile.__libsndfile_version__

@vi-dev0
Copy link
Author

vi-dev0 commented Apr 1, 2023

0.12.1 soundfile.__version__
1.0.28 soundfile.__libsndfile_version__

@bastibe
Copy link
Owner

bastibe commented Apr 1, 2023

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.

@vi-dev0
Copy link
Author

vi-dev0 commented Apr 1, 2023

image
image

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.6 LTS
Release:        20.04
Codename:       focal

unfortunately it didn't help

@bastibe
Copy link
Owner

bastibe commented Apr 1, 2023

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.

@vi-dev0
Copy link
Author

vi-dev0 commented Apr 1, 2023

image


image


And it doesn 't help 😢

@bastibe
Copy link
Owner

bastibe commented Apr 1, 2023

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).

@bastibe
Copy link
Owner

bastibe commented Apr 1, 2023

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.

@vi-dev0
Copy link
Author

vi-dev0 commented Apr 1, 2023

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).

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!

@vi-dev0 vi-dev0 closed this as completed Apr 1, 2023
@vi-dev0 vi-dev0 changed the title soundfile.LibsndfileError: Error opening: File contains data in an unimplemented format. [RESOLVED] soundfile.LibsndfileError: Error opening: File contains data in an unimplemented format. Apr 1, 2023
@bastibe
Copy link
Owner

bastibe commented Apr 1, 2023

Glad it worked!

@wshapple
Copy link

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).

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?

@mmuneeburahman
Copy link

mmuneeburahman commented Apr 2, 2024

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.

@PPeiMi
Copy link

PPeiMi commented Jul 11, 2024

apt-get update
apt-get install libsndfile1
apt-get install ffmpeg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants