File size: 756 Bytes
9202468
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
28
29
30
31
32
33
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