
#example: python tts.py Dorothy test.mp4 "I am not from kansas"

import os
import sys

if(len(sys.argv)!=4):
    print("Error: usage: voice outfile \"text to speak\"" )
    exit(0)

try:
    from elevenlabs import play, save
    from elevenlabs.client import ElevenLabs
except:
    print("elevenlabs lib not installed try pip install elevenlabs")
    exit()
    
API_KEY = os.environ.get("elevenlabs_api_key")  # Your API key for authentication

if(API_KEY is None or len(API_KEY)==0):
    print("Error: elevenlabs_api_key env var not yet set")
    exit(0)
    
home = os.path.dirname(os.path.realpath(__file__))

#ffmpeg = home + '\\ffmpeg_gui\\ffmpeg\\bin\\'
#os.environ['PATH'] += os.pathsep + ffmpeg

#script_name = sys.argv[0]
user_voice = sys.argv[1]
out_file = sys.argv[2]
tts_text = sys.argv[3]

client = ElevenLabs(
  api_key = API_KEY
)

audio = client.generate(
  text  = tts_text,
  voice = user_voice,
  model = "eleven_multilingual_v2"
)

save(audio, out_file)
print("complete")