jinggujiwoo7 commited on
Commit
187a6f4
1 Parent(s): 75c9c6e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -0
app.py CHANGED
@@ -45,6 +45,13 @@ def validate_sentence(sentence):
45
  return "Please enter a sentence."
46
  return sentence
47
 
 
 
 
 
 
 
 
48
  with gr.Blocks() as app:
49
  with gr.Row():
50
  sentence_input = gr.Textbox(label="Enter Your Sentence Here")
@@ -53,6 +60,7 @@ with gr.Blocks() as app:
53
  check_pronunciation_button = gr.Button("Check Pronunciation")
54
  pronunciation_feedback = gr.Textbox(label="Pronunciation Feedback")
55
  pronunciation_score = gr.Number(label="Pronunciation Accuracy Score: 0 (No Match) ~ 1 (Perfect)")
 
56
 
57
  sentence_input.change(
58
  validate_sentence,
@@ -66,4 +74,10 @@ with gr.Blocks() as app:
66
  outputs=[pronunciation_feedback, pronunciation_score]
67
  )
68
 
 
 
 
 
 
 
69
  app.launch(debug=True)
 
45
  return "Please enter a sentence."
46
  return sentence
47
 
48
+ def download_audio(file_info):
49
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmpfile:
50
+ sf.write(tmpfile.name, data=file_info[1], samplerate=44100, format='WAV')
51
+ tmpfile.seek(0)
52
+ with open(tmpfile.name, "rb") as f:
53
+ return f.read(), "recording.wav"
54
+
55
  with gr.Blocks() as app:
56
  with gr.Row():
57
  sentence_input = gr.Textbox(label="Enter Your Sentence Here")
 
60
  check_pronunciation_button = gr.Button("Check Pronunciation")
61
  pronunciation_feedback = gr.Textbox(label="Pronunciation Feedback")
62
  pronunciation_score = gr.Number(label="Pronunciation Accuracy Score: 0 (No Match) ~ 1 (Perfect)")
63
+ download_audio_button = gr.Button("Download Recording")
64
 
65
  sentence_input.change(
66
  validate_sentence,
 
74
  outputs=[pronunciation_feedback, pronunciation_score]
75
  )
76
 
77
+ download_audio_button.click(
78
+ download_audio,
79
+ inputs=[audio_input],
80
+ outputs=gr.File(label="Download Your Recording")
81
+ )
82
+
83
  app.launch(debug=True)