forked from LiveCarta/ContentGeneration
35 lines
983 B
Python
35 lines
983 B
Python
from elevenlabs.client import ElevenLabs
|
|
from elevenlabs.play import play
|
|
import os
|
|
import json
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
ELEVENLABS_API_KEY = os.getenv('ELEVENLABS_API_KEY')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
script_path = "reel_script.json"
|
|
with open(script_path, "r") as f:
|
|
reel_data = json.load(f)
|
|
|
|
client = ElevenLabs(
|
|
api_key=ELEVENLABS_API_KEY
|
|
)
|
|
for shot in reel_data["shots"]:
|
|
print(shot["shot_number"], shot["voiceover"])
|
|
prompt = shot["voiceover"]
|
|
audio = client.text_to_speech.convert(
|
|
text=prompt,
|
|
voice_id="JBFqnCBsd6RMkjVDRZzb",
|
|
model_id="eleven_multilingual_v2",
|
|
output_format="mp3_44100_128",
|
|
)
|
|
|
|
audio_bytes = b"".join(audio)
|
|
|
|
if not os.path.exists("audios"):
|
|
os.makedirs("audios")
|
|
with open(f"audios/output_{shot["shot_number"]}.mp3", "wb") as f:
|
|
f.write(audio_bytes) |