Spaces:
Runtime error
Runtime error
File size: 679 Bytes
8d59b1d abc2da4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
import os
import speech_recognition as sr
from elevenlabs import generate, play, set_api_key
set_api_key(os.environ['ELEVEN_API_KEY'])
class AudioInterface:
def listen(self) -> str:
recognizer = sr.Recognizer()
with sr.Microphone() as source:
print("Say something!")
audio = recognizer.listen(source)
text = recognizer.recognize_whisper_api(
audio,
api_key=os.environ['OPENAI_API_KEY'],
)
return text
def speak(self, text):
audio = generate(
text=text,
voice='Bella',
model='eleven_monolingual_v1'
)
return play(audio) |