lugia19 / elevenlabslib

Full python wrapper for the elevenlabs API.
MIT License
148 stars 27 forks source link

RuntimeError: Error opening <_io.BytesIO object at 0x0000027693FCF830> #9

Closed JarodMica closed 1 year ago

JarodMica commented 1 year ago

Issue when trying to play the genereated audio from Eleven Labs, resulting in this error here:

Exception has occurred: RuntimeError
Error opening <_io.BytesIO object at 0x0000027693FCF830>: File contains data in an unknown format.
  File "C:\Users\jmica\Desktop\Helper\Vivy\gpt_assistant.py", line 330, in generate_voice
    self.voice.generate_and_play_audio(f"{response}", playInBackground=False)
  File "C:\Users\jmica\Desktop\Helper\Vivy\gpt_assistant.py", line 240, in assistantP
    self.generate_voice("I'm listening.", useEL)
  File "C:\Users\jmica\Desktop\Helper\Vivy\assistantp.py", line 8, in <module>
    chatbot.assistantP(save_foldername=foldername, useEL=True)
RuntimeError: Error opening <_io.BytesIO object at 0x0000027693FCF830>: File contains data in an unknown format.

I can verify it reads and talks to the EL API as the audio file is generated in my EL history, but it does not play when ran in my script.

The same error, but additional info from the terminal:

 File "C:\Users\jmica\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Users\jmica\AppData\Local\Programs\Python\Python310\lib\runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "c:\Users\jmica\.vscode\extensions\ms-python.python-2023.4.0\pythonFiles\lib\python\debugpy\__main__.py", line 39, in <module>
    cli.main()
  File "c:\Users\jmica\.vscode\extensions\ms-python.python-2023.4.0\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 430, in main
    run()
  File "c:\Users\jmica\.vscode\extensions\ms-python.python-2023.4.0\pythonFiles\lib\python\debugpy/..\debugpy\server\cli.py", line 284, in run_file
    runpy.run_path(target, run_name="__main__")
  File "c:\Users\jmica\.vscode\extensions\ms-python.python-2023.4.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 321, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "c:\Users\jmica\.vscode\extensions\ms-python.python-2023.4.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 135, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "c:\Users\jmica\.vscode\extensions\ms-python.python-2023.4.0\pythonFiles\lib\python\debugpy\_vendored\pydevd\_pydevd_bundle\pydevd_runpy.py", line 124, in _run_code
    exec(code, run_globals)
  File "C:\Users\jmica\Desktop\Helper\Vivy\assistantp.py", line 8, in <module>
    chatbot.assistantP(save_foldername=foldername, useEL=True)
  File "C:\Users\jmica\Desktop\Helper\Vivy\gpt_assistant.py", line 240, in assistantP
    self.generate_voice("I'm listening.", useEL)
  File "C:\Users\jmica\Desktop\Helper\Vivy\gpt_assistant.py", line 330, in generate_voice
    self.voice.generate_and_play_audio(f"{response}", playInBackground=False)
  File "C:\Users\jmica\AppData\Local\Programs\Python\Python310\lib\site-packages\elevenlabslib\ElevenLabsVoice.py", line 153, in generate_and_play_audio
    play_audio_bytes(self.generate_audio_bytes(prompt, stability, similarity_boost), playInBackground, portaudioDeviceID)
  File "C:\Users\jmica\AppData\Local\Programs\Python\Python310\lib\site-packages\elevenlabslib\helpers.py", line 68, in play_audio_bytes
    soundFile = sf.SoundFile(audioFile)
  File "C:\Users\jmica\AppData\Local\Programs\Python\Python310\lib\site-packages\soundfile.py", line 629, in __init__
    self._file = self._open(file, mode_int, closefd)
  File "C:\Users\jmica\AppData\Local\Programs\Python\Python310\lib\site-packages\soundfile.py", line 1183, in _open
    _error_check(_snd.sf_error(file_ptr),
  File "C:\Users\jmica\AppData\Local\Programs\Python\Python310\lib\site-packages\soundfile.py", line 1357, in _error_check
    raise RuntimeError(prefix + _ffi.string(err_str).decode('utf-8', 'replace'))
RuntimeError: Error opening <_io.BytesIO object at 0x000002923C3BF600>: File contains data in an unknown format.
lugia19 commented 1 year ago

It looks as if it's using an outdated version of libsndfile, similar to this issue https://github.com/lugia19/elevenlabslib/issues/7.

Soundfile first tries to load any version of libsndfile that's found in your $PATH, so it's likely you've got an older version installed. See this issue for more info: https://github.com/bastibe/python-soundfile/issues/302

lugia19 commented 1 year ago

I'm going to mark this as closed as there was no further info given, and it seems like the issue was identified correctly.