Replace "audiodata = AudioSegment.fromfile(BytesIO(chunk), format="mp3")" using other…
- User
Replace "audio_data = AudioSegment.from_file(BytesIO(chunk), format="mp3")" using other libraries, make 3 variants:
async def audio_consumer(): """Continuously play audio chunks as they become available.""" while True: if not audio_queue.empty(): chunk = audio_queue.get() # Convertir l'audio MP3 en données WAV en mémoire audio_data = AudioSegment.from_file(BytesIO(chunk), format="mp3") wav_bytes = BytesIO() audio_data.export(wav_bytes, format="wav") wav_bytes.seek(0) # Important pour remettre le curseur au début du BytesIO # Jouer l'audio directement à partir de la mémoire sound = pygame.mixer.Sound(file=wav_bytes) sound.play() await asyncio.sleep(0.01) # Sleep briefly to yield control to the event loop
- Assistant
Below are three variants of the function using different libraries to replace
AudioSegment.from_file: - User
Traceback (most recent call last): File "c:\Users\Brahim\Desktop\Python\WoW\TTS\tts-test2.py", line 54, in loop.run_until_complete(main()) File "C:\Users\Brahim\AppData\Local\Programs\Python\Python312\Lib\asyncio\base_events.py", line 664, in run_until_complete return future.result() ^^^^^^^^^^^^^^^ File "c:\Users\Brahim\Desktop\Python\WoW\TTS\tts-test2.py", line 46, in main await asyncio.gather( File "c:\Users\Brahim\Desktop\Python\WoW\TTS\tts-test2.py", line 27, in audio_consumer audio_data = AudioSegment.from_file(BytesIO(chunk), format="mp3") ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Brahim\AppData\Local\Programs\Python\Python312\Lib\site-packages\pydub\audio_segment.py", line 773, in from_file raise CouldntDecodeError( pydub.exceptions.CouldntDecodeError: Decoding failed. ffmpeg returned error code: 4294967274
- Assistant