Spaces:
Runtime error
Runtime error
File size: 910 Bytes
9dfbb06 74ba51d 9dfbb06 74ba51d ce632d0 74ba51d 9dfbb06 74ba51d 1669389 9dfbb06 74ba51d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
import gradio as gr
from gradio_unifiedaudio import UnifiedAudio
from pathlib import Path
import numpy as np
import time
example = UnifiedAudio().example_inputs()
dir_ = Path(__file__).parent
def add_to_stream(audio, instream):
if instream is None:
ret = audio
else:
ret = (audio[0], np.concatenate((instream[1], audio[1])))
return audio, ret
def stop_recording(audio):
return UnifiedAudio(value=audio, streaming=False)
def stop_playing():
return UnifiedAudio(value=None, streaming=True), None
with gr.Blocks() as demo:
mic = UnifiedAudio(sources=["microphone"], streaming=True)
stream = gr.State()
mic.stop_recording(stop_recording, stream, mic)
# mic.end(lambda: [None, None], None, [mic, stream])
mic.end(stop_playing, None, [mic, stream])
mic.stream(add_to_stream, [mic, stream], [mic, stream])
if __name__ == '__main__':
demo.launch() |