kamau1 commited on
Commit
d7da748
·
1 Parent(s): 497f50e

Update modules/app.py

Browse files
Files changed (1) hide show
  1. modules/app.py +11 -8
modules/app.py CHANGED
@@ -26,9 +26,7 @@ ngrok.set_auth_token("2UAhCqf5zP0cCgJzeadNANkbIqx_7ZJvhkDSNWccqMX2hyxXP")
26
  # Set up OpenAI API credentials
27
  openai.api_key = 'YOUR_API_KEY'
28
 
29
- @app.route('/')
30
- def home():
31
- html_content = """
32
  <!DOCTYPE html>
33
  <html>
34
  <head>
@@ -45,16 +43,20 @@ def home():
45
  </body>
46
  </html>
47
  """
 
 
 
 
48
  return html_content
49
 
50
 
51
  def handle_form():
52
- r = sr.Recognizer()
53
- with sr.Microphone() as source:
54
  print("Listening...")
55
  audio = r.listen(source)
56
 
57
- try:
58
  result = r.recognize_google(audio)
59
  print("result2:")
60
  print(r.recognize_google(audio, show_all=True))
@@ -74,10 +76,11 @@ try:
74
  tts.save(filename)
75
  playsound(filename)
76
  os.remove(filename)
77
- except sr.UnknownValueError:
78
  print("Google Speech Recognition could not understand audio")
79
- except sr.RequestError as e:
80
  print("Could not request results from Google Speech Recognition service; {0}".format(e))
 
81
 
82
  @app.route('/', methods=['POST'])
83
  def submit_textarea():
 
26
  # Set up OpenAI API credentials
27
  openai.api_key = 'YOUR_API_KEY'
28
 
29
+ html_content = """
 
 
30
  <!DOCTYPE html>
31
  <html>
32
  <head>
 
43
  </body>
44
  </html>
45
  """
46
+
47
+ @app.route('/')
48
+ def home():
49
+
50
  return html_content
51
 
52
 
53
  def handle_form():
54
+ r = sr.Recognizer()
55
+ with sr.Microphone() as source:
56
  print("Listening...")
57
  audio = r.listen(source)
58
 
59
+ try:
60
  result = r.recognize_google(audio)
61
  print("result2:")
62
  print(r.recognize_google(audio, show_all=True))
 
76
  tts.save(filename)
77
  playsound(filename)
78
  os.remove(filename)
79
+ except sr.UnknownValueError:
80
  print("Google Speech Recognition could not understand audio")
81
+ except sr.RequestError as e:
82
  print("Could not request results from Google Speech Recognition service; {0}".format(e))
83
+ return html_content
84
 
85
  @app.route('/', methods=['POST'])
86
  def submit_textarea():