Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +12 -15
- requirements.txt +0 -1
app.py
CHANGED
|
@@ -4,27 +4,22 @@ import openai
|
|
| 4 |
import tempfile
|
| 5 |
from gtts import gTTS
|
| 6 |
import os
|
| 7 |
-
import
|
| 8 |
|
| 9 |
# API key ophalen
|
| 10 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 11 |
|
| 12 |
-
# Init pygame mixer
|
| 13 |
-
pygame.mixer.init()
|
| 14 |
-
|
| 15 |
-
# Gesprekshistorie
|
| 16 |
gesprek = []
|
| 17 |
|
| 18 |
def gesprek_met_ai(audio):
|
| 19 |
global gesprek
|
| 20 |
|
| 21 |
-
#
|
| 22 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
|
| 23 |
tmp.write(audio)
|
| 24 |
tmp_path = tmp.name
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
import speech_recognition as sr
|
| 28 |
r = sr.Recognizer()
|
| 29 |
with sr.AudioFile(tmp_path) as source:
|
| 30 |
audio_data = r.record(source)
|
|
@@ -46,22 +41,24 @@ def gesprek_met_ai(audio):
|
|
| 46 |
antwoord = response.choices[0].message.content
|
| 47 |
gesprek.append(f"Klant: {antwoord}")
|
| 48 |
|
| 49 |
-
#
|
| 50 |
tts = gTTS(antwoord, lang='nl')
|
| 51 |
audio_output = os.path.join(tempfile.gettempdir(), "ai_response.mp3")
|
| 52 |
tts.save(audio_output)
|
| 53 |
|
| 54 |
-
|
| 55 |
-
pygame.mixer.music.play()
|
| 56 |
-
|
| 57 |
-
return tekst, antwoord
|
| 58 |
|
|
|
|
| 59 |
interface = gr.Interface(
|
| 60 |
fn=gesprek_met_ai,
|
| 61 |
inputs=gr.Audio(source="microphone", type="binary"),
|
| 62 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
title="🎤 Trusted Advisor AI",
|
| 64 |
-
description="
|
| 65 |
)
|
| 66 |
|
| 67 |
interface.launch()
|
|
|
|
| 4 |
import tempfile
|
| 5 |
from gtts import gTTS
|
| 6 |
import os
|
| 7 |
+
import speech_recognition as sr
|
| 8 |
|
| 9 |
# API key ophalen
|
| 10 |
openai.api_key = os.getenv("OPENAI_API_KEY")
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
gesprek = []
|
| 13 |
|
| 14 |
def gesprek_met_ai(audio):
|
| 15 |
global gesprek
|
| 16 |
|
| 17 |
+
# Audio opslaan
|
| 18 |
with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
|
| 19 |
tmp.write(audio)
|
| 20 |
tmp_path = tmp.name
|
| 21 |
|
| 22 |
+
# Spraakherkenning
|
|
|
|
| 23 |
r = sr.Recognizer()
|
| 24 |
with sr.AudioFile(tmp_path) as source:
|
| 25 |
audio_data = r.record(source)
|
|
|
|
| 41 |
antwoord = response.choices[0].message.content
|
| 42 |
gesprek.append(f"Klant: {antwoord}")
|
| 43 |
|
| 44 |
+
# Spraak van antwoord genereren
|
| 45 |
tts = gTTS(antwoord, lang='nl')
|
| 46 |
audio_output = os.path.join(tempfile.gettempdir(), "ai_response.mp3")
|
| 47 |
tts.save(audio_output)
|
| 48 |
|
| 49 |
+
return tekst, antwoord, audio_output
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
+
# Gradio UI
|
| 52 |
interface = gr.Interface(
|
| 53 |
fn=gesprek_met_ai,
|
| 54 |
inputs=gr.Audio(source="microphone", type="binary"),
|
| 55 |
+
outputs=[
|
| 56 |
+
gr.Textbox(label="Herkenning van jouw spraak"),
|
| 57 |
+
gr.Textbox(label="AI-reactie"),
|
| 58 |
+
gr.Audio(label="Luister naar AI-reactie")
|
| 59 |
+
],
|
| 60 |
title="🎤 Trusted Advisor AI",
|
| 61 |
+
description="Spreek in je microfoon en voer een gesprek met een AI-klant. De reactie hoor je terug in audio en tekst."
|
| 62 |
)
|
| 63 |
|
| 64 |
interface.launch()
|
requirements.txt
CHANGED
|
@@ -3,4 +3,3 @@ gradio
|
|
| 3 |
openai
|
| 4 |
speechrecognition
|
| 5 |
gtts
|
| 6 |
-
pygame
|
|
|
|
| 3 |
openai
|
| 4 |
speechrecognition
|
| 5 |
gtts
|
|
|