File size: 1,246 Bytes
9202468
 
 
 
 
 
 
69f88db
9202468
 
69f88db
 
9202468
 
69f88db
 
 
 
 
 
 
 
 
 
 
 
9202468
 
 
69f88db
 
9202468
 
 
 
69f88db
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import os
from elevenlabs import generate, play
from elevenlabs import set_api_key
from elevenlabs import generate, stream


class SpeechService:
    def __init__(self, voice_id="Bella", model_id="eleven_monolingual_v1"):
        account_sid = os.environ["ELEVENLABS_API_KEY"]
        set_api_key(account_sid)
        self._voice_id = voice_id
        self._model_id = model_id


    # def print_models(self):
    #     models = generate()
    #     for model in models:
    #         print (model["id"], model["name"])


    def print_voices(self):
        from elevenlabs.api import Voices
        voices = Voices.from_api()
        for voice in voices:
            print (voice)

    def speak(self, prompt):
        # audio = generate(
        # text=prompt,
        # voice=self._voice_id,
        # model=self._model_id,
        # )
        # play(audio)
        audio_stream = generate(
            text=prompt,
            voice=self._voice_id,
            model=self._model_id,
            stream=True
            )
        # stream(audio_stream)
        audio = b""
        for chunk in audio_stream:
            if chunk is not None:
                audio += chunk
                # play(chunk)
        play(audio)
        return