Zeebra commited on
Commit
9ca7f57
1 Parent(s): a330536

both for linux and windows

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -3,8 +3,8 @@ import openai
3
  from decouple import config
4
  from gtts import gTTS
5
  import os
6
- import win32com.client
7
- import pythoncom
8
  import config
9
 
10
  openai.api_key = config.API_KEYS['openai']
@@ -14,10 +14,6 @@ messages = [
14
  {"role": "system", "content": "You are a helpful assistant."},
15
  ]
16
 
17
-
18
- # language = 'en'
19
-
20
-
21
  # Main method goes here
22
  def decipher(audio):
23
  global messages
@@ -34,14 +30,20 @@ def decipher(audio):
34
  )
35
 
36
  system_message = response["choices"][0]["message"]["content"]
37
- pythoncom.CoInitialize()
38
- speaker = win32com.client.Dispatch("SAPI.SpVoice")
39
- speaker.Speak(system_message)
40
- # myobj = gTTS(text=system_message, lang=language, slow=False)
41
- # myobj.save("welcome.mp3")
42
- # # Playing the converted file
43
- # os.system("start welcome.mp3")
44
- messages.append({"role": "assistant", "content": system_message},)
 
 
 
 
 
 
45
 
46
  chat_transcript = ""
47
  for message in messages:
@@ -50,8 +52,7 @@ def decipher(audio):
50
 
51
  return chat_transcript
52
 
53
-
54
  # Using Gradio's audio Interface
55
  interface = gr.Interface(fn=decipher, inputs=gr.Audio(
56
  source="microphone", type="filepath"), outputs="text")
57
- interface.launch(share=True)
 
3
  from decouple import config
4
  from gtts import gTTS
5
  import os
6
+ import pydub
7
+ import io
8
  import config
9
 
10
  openai.api_key = config.API_KEYS['openai']
 
14
  {"role": "system", "content": "You are a helpful assistant."},
15
  ]
16
 
 
 
 
 
17
  # Main method goes here
18
  def decipher(audio):
19
  global messages
 
30
  )
31
 
32
  system_message = response["choices"][0]["message"]["content"]
33
+ messages.append({"role": "assistant", "content": system_message})
34
+
35
+ # Convert the text to audio using gTTS
36
+ tts = gTTS(text=system_message, lang='en')
37
+ audio_data = io.BytesIO()
38
+ tts.write_to_fp(audio_data)
39
+
40
+ # Convert the audio to a playable format using pydub
41
+ audio_data.seek(0)
42
+ audio = pydub.AudioSegment.from_file(audio_data, format="mp3")
43
+
44
+ # Play the audio using VLC
45
+ player = pydub.playback.play
46
+ player(audio)
47
 
48
  chat_transcript = ""
49
  for message in messages:
 
52
 
53
  return chat_transcript
54
 
 
55
  # Using Gradio's audio Interface
56
  interface = gr.Interface(fn=decipher, inputs=gr.Audio(
57
  source="microphone", type="filepath"), outputs="text")
58
+ interface.launch(share=True)