Got this error, fix it : Hello from the pygame community.…
- User
Got this error, fix it : Hello from the pygame community. https://www.pygame.org/contribute.html Traceback (most recent call last): File "c:\Users\Brahim\Desktop\Python\WoW\TTS\tts.py", line 171, in asyncio.run(main()) File "C:\Users\Brahim\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 194, in run return runner.run(main) ^^^^^^^^^^^^^^^^ File "C:\Users\Brahim\AppData\Local\Programs\Python\Python312\Lib\asyncio\runners.py", line 118, in run return self.loop.run_until_complete(task) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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.py", line 168, in main await WoWTTS.play("Savez-vous, Brahim, qu'il n'y a rien de pire que de se retrouver avec un pantalon déchiré au beau milieu de nulle part !. Bonjour ! Assurez-vous toujours de la bonne réputation de votre tailleur. Il n'y a rien de pire que de se retrouver avec un pantalon déchiré au beau milieu de nulle part !", 'male', 'humanoïde', 0, 0.5, None) File "c:\Users\Brahim\Desktop\Python\WoW\TTS\tts.py", line 100, in play await self.stream_tts(text_to_read, voice, formatted_pitch) File "c:\Users\Brahim\Desktop\Python\WoW\TTS\tts.py", line 134, in stream_tts self.play_audio(audio_segment) File "c:\Users\Brahim\Desktop\Python\WoW\TTS\tts.py", line 144, in play_audio stream = p.open( ^^^^^^^ File "C:\Users\Brahim\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyaudio_init.py", line 639, in open stream = PyAudio.Stream(self, *args, **kwargs) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\Brahim\AppData\Local\Programs\Python\Python312\Lib\site-packages\pyaudio_init_.py", line 441, in init self._stream = pa.open(**arguments) ^^^^^^^^^^^^^^^^^^^^ OSError: [Errno -9996] Invalid output device (no default output device)
- Assistant
The error message
[Errno -9996] Invalid output device (no default output device)indicates that PyAudio (the library you are using for handling audio) is unable to open an audio stream because it cannot find a valid output device. This usually happens when there is an issue with the audio configuration on your system, or if the audio device is not available or not recognized correctly.Here are several steps to troubleshoot and attempt to fix this issue:
- User
Look, here is the code for context, where to fix ? # Async function to perform Text-to-Speech streaming async def stream_tts(self, text: str, voice: str, formated_pitch: str) -> None: communicate = edge_tts.Communicate(text, voice, pitch = formated_pitch) full_audio_data = BytesIO()
code - Assistant
The given code snippet seems to have an issue with using an invalid or non-existent default audio output device, as indicated by the
OSError: [Errno -9996] Invalid output device (no default output device). It appears your code might be missing the PyAudio object instantiation (p = pyaudio.PyAudio()), and it does not include the cleanup in the correct location (p.terminate()).Here is how you can update the function to instantiate the PyAudio object (), use it to open the stream, and properly terminate it after use: