Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stream and play #114

Open
RobinWitch opened this issue Aug 19, 2024 · 4 comments
Open

Stream and play #114

RobinWitch opened this issue Aug 19, 2024 · 4 comments

Comments

@RobinWitch
Copy link

It's so appealing for me to use streaming.

for (sampling_rate, audio_chunk) in generate(text, description, chunk_size_in_s):
  # You can do everything that you need with the chunk now
  # For example: stream it, save it, play it.
  print(audio_chunk.shape) 

But I'm sorry, I'm a beginner. This is my first time learning about and wanting to use the stream feature. Could you provide a specific example of streaming it and playing it?"

@tsdocode
Copy link

I have a gradio example for it:
https://gist.github.com/tsdocode/6be4bc8d5c63321d933d404adbfdfa7a

@RobinWitch
Copy link
Author

Thank you very much, it helps me a lot !!!

I have a gradio example for it: https://gist.github.com/tsdocode/6be4bc8d5c63321d933d404adbfdfa7a

@cesinsingapore
Copy link

this is my example to make it more smooth, but i still heard static between the chunks, if someone can enhance it to play it smoother please make a revision
https://gist.github.com/cesinsingapore/5147b0fcd63ba6aa22e0faa1a52ba249

@tsdocode
Copy link

This small script help add crossfade and avoid static noise between chunk

    combined_audio = AudioSegment.silent(duration=100)

    # Process each audio chunk and apply crossfade
    for chunk in audio_chunks:
        audio_segment = AudioSegment.from_raw(
            io.BytesIO(chunk), sample_width=2, frame_rate=44100, channels=1
        )

        if len(combined_audio) > 0:
            chunk_length_ms = (len(chunk) / 44100) * 1000
            crossfade_duration = int(0.1 * chunk_length_ms)
        else:
            crossfade_duration = 0

        combined_audio = combined_audio.append(audio_segment, crossfade=crossfade_duration)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants