Spaces:
Runtime error
Runtime error
File size: 1,463 Bytes
d47e55c |
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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
from elevenlabs import clone, generate, play, set_api_key, VOICES_CACHE, voices
from elevenlabs.api import History
import os
os.environ['ELEVENLABS_API_KEY'] = ''
set_api_key(os.environ.get("ELEVENLABS_API_KEY"))
def with_custom_voice(podcaster, guest, description, prompt, file_path):
name = f'Podcast between {podcaster} and {guest}'
temp = name.replace(' ', '_')
audio_path = f'{temp}.mp3'
voice = clone(
name=f'Podcast between {podcaster} and {guest}',
description=description,
files=[file_path,],
)
audio = generate(text=prompt, voice=voice)
play(audio)
try:
with open(audio_path, 'wb') as f:
f.write(audio)
return audio_path
except Exception as e:
print(e)
return ""
def with_premade_voice(prompt, voice):
audio_path = f'{voice}.mp3'
audio = generate(
text=prompt,
voice=voice,
model="eleven_monolingual_v1"
)
play(audio)
try:
with open(audio_path, 'wb') as f:
f.write(audio)
return audio_path
except Exception as e:
print(e)
return ""
def get_voices():
names = []
v_list = voices()
for v in v_list:
names.append(v.name)
return names
# usage
# if __name__ == '__main__':
# print(get_voices())
# print(with_premade_voice(prompt='Hi! My name is Bella, nice to meet you!', voice='Bella'))
|