Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,35 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
from pydub import AudioSegment
|
| 4 |
-
from io import BytesIO
|
| 5 |
-
import tempfile
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
except Exception as e:
|
| 19 |
-
return f"Error loading audio file: {e}"
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
text = recognizer.recognize_google(audio_data)
|
| 31 |
-
return text
|
| 32 |
-
except sr.UnknownValueError:
|
| 33 |
-
return "Google Speech Recognition could not understand audio"
|
| 34 |
-
except sr.RequestError as e:
|
| 35 |
-
return f"Could not request results from Google Speech Recognition service; {e}"
|
| 36 |
|
| 37 |
-
# Gradio
|
| 38 |
iface = gr.Interface(
|
| 39 |
-
fn=
|
| 40 |
-
inputs="
|
| 41 |
outputs="text",
|
| 42 |
title="Voice to Text Converter",
|
| 43 |
-
description="
|
| 44 |
)
|
| 45 |
|
| 46 |
iface.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
+
# Function to send audio to Groq API and get transcription
|
| 5 |
+
def transcribe(audio):
|
| 6 |
+
# Load audio data
|
| 7 |
+
audio_data = audio.read()
|
| 8 |
+
|
| 9 |
+
# Replace these placeholders with your actual Groq API endpoint and headers
|
| 10 |
+
groq_api_endpoint = "https://api.groq.com/transcribe" # Example endpoint
|
| 11 |
+
headers = {
|
| 12 |
+
"Authorization": "Bearer YOUR_GROQ_API_KEY",
|
| 13 |
+
"Content-Type": "audio/wav",
|
| 14 |
+
}
|
|
|
|
|
|
|
| 15 |
|
| 16 |
+
# Send audio to Groq API
|
| 17 |
+
response = requests.post(groq_api_endpoint, headers=headers, data=audio_data)
|
| 18 |
+
|
| 19 |
+
# Parse response
|
| 20 |
+
if response.status_code == 200:
|
| 21 |
+
result = response.json()
|
| 22 |
+
return result.get("transcription", "No transcription available.")
|
| 23 |
+
else:
|
| 24 |
+
return f"Error: {response.status_code}, {response.text}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
+
# Gradio interface
|
| 27 |
iface = gr.Interface(
|
| 28 |
+
fn=transcribe,
|
| 29 |
+
inputs=gr.Audio(source="microphone", type="file"),
|
| 30 |
outputs="text",
|
| 31 |
title="Voice to Text Converter",
|
| 32 |
+
description="Record your voice, and it will be transcribed into text using Groq API."
|
| 33 |
)
|
| 34 |
|
| 35 |
iface.launch()
|