Spaces:
Sleeping
Sleeping
File size: 1,061 Bytes
8824f1d a47bd1b 8824f1d c3f10f2 8824f1d 7c82bbb 8824f1d c3f10f2 8824f1d |
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 34 35 36 |
import gradio as gr
import soundfile as sf
import os
import spaces
from s2s import generate
def get_tmp_path(file_name: str):
temp_dir = "tempor"
if not os.path.exists(temp_dir):
os.makedirs(temp_dir)
return os.path.join(temp_dir, file_name)
@spaces.GPU
def process_audio(audio_file):
result_audio_arr, sample_rate = generate(audio_file, lambda msg: gr.Info(msg))
gr.Info("Writing response")
target_path = get_tmp_path("processed_audio.wav")
sf.write(target_path, result_audio_arr, sample_rate)
return target_path
demo = gr.Interface(
fn=process_audio,
inputs=[gr.Audio(label="User Input", type="filepath", format="wav")],
outputs=[gr.Audio(label="Response")],
title="Speech to Speech with Mini Omni",
description='<h2 style="text-align:center;">Ask anything in English and get the audio response!</h2>',
article="Generation will take a while. Be patient! :)</br>Wait for a few seconds before your recorded audio is fully uploaded.</br>Retry if you encounter any error.",
)
demo.launch()
|