lodhrangpt commited on
Commit
29b48cb
·
verified ·
1 Parent(s): fd4c6f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -1,8 +1,16 @@
1
  import gradio as gr
2
  import requests
3
-
4
- # Function to send audio to Groq API and get transcription
5
- def transcribe(audio_path):
 
 
 
 
 
 
 
 
6
  # Read audio file in binary mode
7
  with open(audio_path, "rb") as audio_file:
8
  audio_data = audio_file.read()
@@ -12,7 +20,7 @@ def transcribe(audio_path):
12
 
13
  # Replace 'YOUR_GROQ_API_KEY' with your actual Groq API key
14
  headers = {
15
- "Authorization": "Bearer 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",
16
  }
17
 
18
  # Prepare the files and data for the request
@@ -37,11 +45,11 @@ def transcribe(audio_path):
37
 
38
  # Gradio interface
39
  iface = gr.Interface(
40
- fn=transcribe,
41
- inputs=gr.Audio(type="filepath"), # Removed 'source' parameter for compatibility
42
  outputs="text",
43
- title="Voice to Text Converter App",
44
-
45
  )
46
 
47
- iface.launch()
 
1
  import gradio as gr
2
  import requests
3
+ from gtts import gTTS # Import gTTS for Text-to-Speech
4
+ import tempfile
5
+
6
+ # Function to convert text to speech and transcribe
7
+ def text_to_speech_transcribe(text):
8
+ # Convert text to speech
9
+ tts = gTTS(text, lang='en')
10
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp_audio:
11
+ audio_path = tmp_audio.name
12
+ tts.save(audio_path)
13
+
14
  # Read audio file in binary mode
15
  with open(audio_path, "rb") as audio_file:
16
  audio_data = audio_file.read()
 
20
 
21
  # Replace 'YOUR_GROQ_API_KEY' with your actual Groq API key
22
  headers = {
23
+ "Authorization": "Bearer YOUR_GROQ_API_KEY", # Replace with your Groq API key
24
  }
25
 
26
  # Prepare the files and data for the request
 
45
 
46
  # Gradio interface
47
  iface = gr.Interface(
48
+ fn=text_to_speech_transcribe,
49
+ inputs="text", # Input text to be converted to speech
50
  outputs="text",
51
+ title="Text to Speech and Transcription",
52
+ description="Enter text to convert it to audio, then transcribe it with the Groq API."
53
  )
54
 
55
+ iface.launch()