I got problem with the following code, the sound played is alterning between sound and…
- User
I got problem with the following code, the sound played is alterning between sound and no sound. Also, know that i want to stream audio else the waiting time is too long : import asyncio import pyaudio import edge_tts
from io import BytesIO from pydub import AudioSegment
Global PyAudio instance
p = pyaudio.PyAudio()
Stream handle
stream = None
async def generate_and_play_sound(text, voice, speed = 0, pitch = 0, volume = 0): global stream, p
If a stream is active, stop and close it
if stream is not None and not stream.is_stopped(): stream.stop_stream() stream.close()
full_audio_data = bytearray()
Fetch audio data from edge_tts
communicate = edge_tts.Communicate(text, voice, rate = format_percent(speed), pitch = format_pitch(pitch), volume = format_percent(volume)) async for chunk in communicate.stream(): if chunk[“type”] == “audio”: try: audio_segment = AudioSegment.from_file(BytesIO(chunk[“data”]), format=“mp3”) raw_data = audio_segment.raw_data
stream = p.open(format=p.get_format_from_width(audio_segment.sample_width), channels=audio_segment.channels, rate=audio_segment.frame_rate, output=True)
stream.write(raw_data) except: print(“woot”)
- Assistant
- User
There is clack clack effect in the sound, like if there is time between chunks. Please you need to find the best solution to have a smooth audio
- Assistant
- User
The sound plays smoothly, ok, but not in stream like i want. Now, the audio loading time is very low for long texts to read. That's not what i want. I want it to play fast and smoothly. DO IT!
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.