Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,6 +11,34 @@ if api_key is None:
|
|
| 11 |
# Initialize the Groq client
|
| 12 |
client = Groq(api_key=api_key)
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
def process_audio(file_path):
|
| 15 |
|
| 16 |
try:
|
|
|
|
| 11 |
# Initialize the Groq client
|
| 12 |
client = Groq(api_key=api_key)
|
| 13 |
|
| 14 |
+
|
| 15 |
+
def processaudio(audio_data):
|
| 16 |
+
try:
|
| 17 |
+
# Entpacken der Audiodaten (Sample-Rate und Numpy-Array)
|
| 18 |
+
sample_rate, samples = audio_data
|
| 19 |
+
|
| 20 |
+
# Temporäre Audiodatei erstellen
|
| 21 |
+
with NamedTemporaryFile(suffix=".wav", delete=True) as tmpfile:
|
| 22 |
+
# Audio als WAV-Datei speichern
|
| 23 |
+
sf.write(tmpfile.name, samples, sample_rate)
|
| 24 |
+
|
| 25 |
+
# Datei erneut öffnen und an Groq senden
|
| 26 |
+
with open(tmpfile.name, "rb") as file:
|
| 27 |
+
transcription = client.audio.transcriptions.create(
|
| 28 |
+
file=(os.path.basename(tmpfile.name), file.read()),
|
| 29 |
+
model="whisper-large-v3-turbo",
|
| 30 |
+
prompt="transcribe",
|
| 31 |
+
language="de",
|
| 32 |
+
response_format="json",
|
| 33 |
+
temperature=0.0
|
| 34 |
+
)
|
| 35 |
+
return transcription.text
|
| 36 |
+
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return f"Ein Fehler ist aufgetreten: {str(e)}"
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
def process_audio(file_path):
|
| 43 |
|
| 44 |
try:
|