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

#8906 still not solve audio play out high delay #9044

Open
steven8274 opened this issue Aug 7, 2024 · 0 comments
Open

#8906 still not solve audio play out high delay #9044

steven8274 opened this issue Aug 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@steven8274
Copy link

steven8274 commented Aug 7, 2024

I met the audio play out high delay problem.However, even I use the #8906 source code to install gradio, the problem not was solved.There is still 3~4s delay and audio playing is not smooth(has some gap, look like lack of audio data).This is my demo code:

import gradio as gr
from pydub import AudioSegment
from time import sleep
import numpy as np
import datetime

audio_list = []
def add_to_stream(audio):
    sleep(0.05)
    global audio_list
    audio_list.append(audio)

with gr.Blocks() as demo:
    inp = gr.Audio(sources=["microphone"], streaming=True)
    inp.stream(add_to_stream, [inp], [])

    stream_as_file_btn = gr.Button("Stream as File")
    stream_as_file_output = gr.Audio(streaming=True)
    stream_as_file_output.autoplay = True

    def stream_file():
        global audio_list
        while True:
            while len(audio_list) == 0:
                print('stream out pull data, but no data available now...')
                sleep(0.05)
            chunk = audio_list[0]
            audio_list = audio_list[1:]
            print('yield audio chunk, samples: {}, cached audio chunks: {}, at: {}'.format(len(chunk[1]), len(audio_list), datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f")))
            yield chunk

    stream_as_file_btn.click(
        stream_file, [], stream_as_file_output
    )


if __name__ == "__main__":
    demo.launch(server_name='0.0.0.0', server_port=8000)

I figured audio data output speed via log, it's coincident with it's sample rate.

Demo usage:
1.click 'stream_as_file_btn' to start audio data fetching.
2.click 'inp' audio component's recording button to start generating audio data.

After about half an second, you will see 'yield audio chunk...', which means audio data beging outputing.

Did I miss something?Thanks in advance.

Originally posted by @steven8274 in #8185 (comment)

@abidlabs abidlabs added the bug Something isn't working label Aug 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants