File size: 1,002 Bytes
84f0350
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dca7ef0
84f0350
 
 
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
37
import gradio as gr
import shutil
import os
import uuid

SAVE_DIR = "recordings"
os.makedirs(SAVE_DIR, exist_ok=True)

def save_and_return(audio_path):
    if audio_path is None:
        return None, "❌ ιŒ²ιŸ³γ•γ‚Œγ¦γ„γΎγ›γ‚“"

    # δΏε­˜ε…ˆγ‚’γƒ¦γƒ‹γƒΌγ‚―γ«οΌˆδΈŠζ›Έγι˜²ζ­’οΌ‰
    new_path = os.path.join(SAVE_DIR, f"{uuid.uuid4().hex}.wav")
    shutil.copy(audio_path, new_path)

    return new_path, "βœ… ιŒ²ιŸ³δΏε­˜οΌ†ε†η”ŸζΊ–ε‚™OK!"

with gr.Blocks() as demo:
    gr.Markdown("# 🎀 ιŒ²ιŸ³γ—γ¦ε†η”Ÿ")

    with gr.Row():
        audio_input = gr.Audio(sources=["microphone"], type="filepath", label="録音")
        audio_output = gr.Audio(label="ιŒ²ιŸ³γ—γŸιŸ³ε£°γ‚’ε†η”Ÿ")

    result_text = gr.Textbox(label="硐果")

    audio_input.change(fn=save_and_return, inputs=audio_input, outputs=[audio_output, result_text])

if __name__ == "__main__":
    demo.launch(
        server_name="0.0.0.0",
        server_port=7860,
        share=True,
        show_error=True
    )