arpit13 commited on
Commit
101895c
·
verified ·
1 Parent(s): 79250f8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -11
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import openai
3
  import os
4
- import speech_recognition as sr
5
 
6
  # Set OpenAI API Key
7
  openai.api_key = os.getenv("TRY_NEW_THINGS")
@@ -22,18 +22,12 @@ def get_groq_response(message):
22
  return f"Error: {str(e)}"
23
 
24
  # Function to convert speech to text
 
25
  def speech_to_text(audio):
26
- # Initialize recognizer
27
- recognizer = sr.Recognizer()
 
28
 
29
- # Convert audio to text
30
- try:
31
- with sr.AudioFile(audio.name) as source:
32
- audio_data = recognizer.record(source)
33
- text = recognizer.recognize_google(audio_data)
34
- return text
35
- except Exception as e:
36
- return f"Error in speech recognition: {str(e)}"
37
 
38
  # Chatbot function
39
  def chatbot(user_input, history=[]):
 
1
  import gradio as gr
2
  import openai
3
  import os
4
+ import openai-whisper
5
 
6
  # Set OpenAI API Key
7
  openai.api_key = os.getenv("TRY_NEW_THINGS")
 
22
  return f"Error: {str(e)}"
23
 
24
  # Function to convert speech to text
25
+
26
  def speech_to_text(audio):
27
+ model = whisper.load_model("base") # Or any model size you prefer
28
+ result = model.transcribe(audio.name) # Use the audio file
29
+ return result['text']
30
 
 
 
 
 
 
 
 
 
31
 
32
  # Chatbot function
33
  def chatbot(user_input, history=[]):