Spaces:
Runtime error
Runtime error
| import os | |
| from elevenlabs import generate, play | |
| from elevenlabs import set_api_key | |
| from elevenlabs import generate, stream | |
| class SpeechService: | |
| def __init__(self): | |
| account_sid = os.environ["ELEVENLABS_API_KEY"] | |
| set_api_key(account_sid) | |
| def speak(self, prompt): | |
| # audio = generate( | |
| # text=prompt, | |
| # voice="Bella", | |
| # model="eleven_monolingual_v1" | |
| # ) | |
| # play(audio) | |
| audio_stream = generate( | |
| text=prompt, | |
| stream=True | |
| ) | |
| # stream(audio_stream) | |
| audio = b"" | |
| for chunk in audio_stream: | |
| if chunk is not None: | |
| audio += chunk | |
| # play(chunk) | |
| play(audio) | |
| return | |