lyimo commited on
Commit
3033421
·
1 Parent(s): e9d8eb9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -17
app.py CHANGED
@@ -39,27 +39,30 @@ def generate_response(transcribed_text):
39
 
40
 
41
  def inference(text):
42
- output_file = "tts_output.wav"
43
- tts = gTTS(text, lang="sw")
44
- tts.save(output_file)
45
- return output_file
 
46
 
47
  def process_audio_and_respond(audio):
48
- text = transcribe(audio)
49
- response_text = generate_response(text)
50
- output_file = inference(response_text)
51
- return response_text, output_file
 
52
 
53
  demo = gr.Interface(
54
- process_audio_and_respond,
55
- gr.inputs.Audio(source="microphone", type="filepath", label="Bonyeza kitufe cha kurekodi na uliza swali lako"),
56
- [gr.outputs.Textbox(label="Jibu (kwa njia ya maandishi)"), gr.outputs.Audio(type="filepath", label="Jibu kwa njia ya sauti (Bofya kusikiliza Jibu)")],
57
- title="Mtaalamu wa Viazi Lishe",
58
- description="Uliza Mtaalamu wetu swali lolote Kuhusu viazi Lishe",
59
- theme="compact",
60
- layout="vertical",
61
- allow_flagging=False,
62
- live=True,
63
  )
64
 
 
65
  demo.launch()
 
39
 
40
 
41
  def inference(text):
42
+ output_file = "tts_output.wav"
43
+ cmd = ['tts', '--text', text, '--out_path', output_file]
44
+ subprocess.run(cmd, check=True)
45
+ return output_file
46
+
47
 
48
  def process_audio_and_respond(audio):
49
+ text = transcribe(audio)
50
+ response_text = generate_response(text)
51
+ output_file = inference(response_text)
52
+ return response_text, output_file
53
+
54
 
55
  demo = gr.Interface(
56
+ process_audio_and_respond,
57
+ gr.inputs.Audio(source="microphone", type="filepath", label="Bonyeza kitufe cha kurekodi na uliza swali lako"),
58
+ [gr.outputs.Textbox(label="Jibu (kwa njia ya maandishi)"), gr.outputs.Audio(type="filepath", label="Jibu kwa njia ya sauti (Bofya kusikiliza Jibu)")],
59
+ title="Mtaalamu wa Viazi Lishe",
60
+ description="Uliza Mtaalamu wetu swali lolote Kuhusu viazi Lishe",
61
+ theme="compact",
62
+ layout="vertical",
63
+ allow_flagging=False,
64
+ live=True,
65
  )
66
 
67
+
68
  demo.launch()