ibvhim commited on
Commit
065e2bf
1 Parent(s): 5a6723b

Create Voicechat-Hindi/app.py

Browse files
Files changed (1) hide show
  1. Voicechat-Hindi/app.py +53 -0
Voicechat-Hindi/app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Deploying AI Voice Chatbot Gradio App."""
2
+ from gradio import Audio, Interface, Textbox
3
+ from typing import Tuple
4
+
5
+ from utils import (TextGenerationPipeline, from_en_translation,
6
+ html_audio_autoplay, stt, to_en_translation, tts,
7
+ tts_to_bytesio)
8
+
9
+ max_answer_length = 100
10
+ desired_language = "hi"
11
+ response_generator_pipe = TextGenerationPipeline(max_length=max_answer_length)
12
+
13
+
14
+ def main(audio: object) -> Tuple[str, str, str, object]:
15
+ """Calls functions for deploying gradio app.
16
+ It responds both verbally and in text
17
+ by taking voice input from user.
18
+ Args:
19
+ audio (object): recorded speech of user
20
+ Returns:
21
+ tuple containing
22
+ - user_speech_text (str) : recognized speech
23
+ - bot_response_hi (str) : translated answer of bot
24
+ - bot_response_en (str) : bot's original answer
25
+ - html (object) : autoplayer for bot's speech
26
+ """
27
+ user_speech_text = stt(audio, desired_language)
28
+ tranlated_text = to_en_translation(user_speech_text, desired_language)
29
+ bot_response_en = response_generator_pipe(tranlated_text)
30
+ bot_response_hi = from_en_translation(bot_response_en, desired_language)
31
+ bot_voice = tts(bot_response_hi, desired_language)
32
+ bot_voice_bytes = tts_to_bytesio(bot_voice)
33
+ html = html_audio_autoplay(bot_voice_bytes)
34
+ return user_speech_text, bot_response_hi, bot_response_en, html
35
+
36
+
37
+ Interface(
38
+ fn=main,
39
+ inputs=[
40
+ Audio(
41
+ source="microphone",
42
+ type="filepath",
43
+ ),
44
+ ],
45
+ outputs=[
46
+ Textbox(label="You said: "),
47
+ Textbox(label="AI: "),
48
+ Textbox(label="AI (English): "),
49
+ "html",
50
+ ],
51
+ live=True,
52
+ allow_flagging="never",
53
+ ).launch(debug=True)