When playing sound in streaming, this code play a sound with a clack clack effect. Fix…
- User
When playing sound in streaming, this code play a sound with a clack clack effect. Fix it. Know that i want to do only audio stream, maybe need a minimum buffer size ? Fix it, and be smart : # Global PyAudio instance p = pyaudio.PyAudio()
async def generate_and_play_sound(text, voice, speed=0, pitch=0, volume=0): # Initialize the audio stream with default settings stream = p.open( format=p.get_format_from_width(2), # Assuming 16-bit audio channels=1, # Mono audio rate=24000, # Sample rate (adjust if needed to match TTS) output=True )
code# Fetch audio data from edge_tts communicate = edge_tts.Communicate(text, voice, rate=format_percent(speed), pitch=format_pitch(pitch), volume=format_percent(volume)) # Process and play audio chunks as they arrive async for chunk in communicate.stream(): if chunk[“type”] == “audio”: try: # Decode the chunk data to raw audio and play it audio_segment = AudioSegment.from_file(BytesIO(chunk[“data”]), format=“mp3”) stream.write(audio_segment.raw_data) except Exception as e: print(“Error processing audio chunk:”, e) # End and close the stream once all audio has been played stream.stop_stream() stream.close() - Assistant
- User
Error processing audio chunk: 'Stream' object has no attribute 'rate'
- Assistant
- User
Le son graisille encore, avec des click click qui s'entendent pendant l'audio, il faut que tu règle ça
- Assistant
- User
Exception has occurred: TypeError 'Stream' object does not support the context manager protocol File "C:\Users\Brahim\Desktop\Python\WoW\TTS\tts-test2.py", line 28, in generate_and_play_sound with stream: File "C:\Users\Brahim\Desktop\Python\WoW\TTS\tts-test2.py", line 64, in main await generate_and_play_sound(text, voice, speed, pitch, volume) File "C:\Users\Brahim\Desktop\Python\WoW\TTS\tts-test2.py", line 70, in asyncio.run(main()) TypeError: 'Stream' object does not support the context manager protocol
- Assistant
- User
Still the clack clack effect. please help help help!!!!
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.