-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgenerate_audio.py
32 lines (28 loc) · 1.03 KB
/
generate_audio.py
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
import soundfile as sf
from elevenlabs import save, stream
from elevenlabs.client import ElevenLabs
from schemas import CharacterResponse, characters, get_character_by_name
from dotenv import load_dotenv
import os
load_dotenv()
client = ElevenLabs(
api_key=os.getenv("ELEVENLABS_API_KEY")
)
def generate_audio(character_response: CharacterResponse):
character = get_character_by_name(character_response.name)
audio_stream = client.generate(
text=character_response.text,
voice=character.voice_id,
stream=True
)
stream(audio_stream)
return character_response
# bytearray_data = bytearray()
# for chunk in audio_stream:
# bytearray_data.extend(chunk)
# bytes_object = bytes(bytearray_data)
# # save(audio_stream, "intermediate/" + character.get_compact_name() + ".wav")
# character_response.audio_bytes = bytes_object
# return character_response
# cr = generate_audio(CharacterResponse(name="Dwayne Johnson", text="I'm Dwayne the rock Johnson"))
# print(cr.audio_bytes)