Search code examples
pythonmpv

elevenlabs-python package vs. google_speech: setting storage path, and limit for characters read-outs


I'm using an python package to play voices known as elevenlabs - here is the link https://github.com/elevenlabs/elevenlabs-python

This package uses mpv to play its audio files,

such that , a script like that will be played:

from elevenlabs import generate, play

audio = generate(
  text="Hi! My name is Bella, nice to meet you!",
  voice="Bella",
  model="eleven_monolingual_v1"
)

play(audio)

I have a specific questions: How to find or set a path for the output audio file?

On the other hand, working with google_speech seems to be very easy, despite the less trained voice for reading text, you can easily save the audio to the desired directory: https://pypi.org/project/google-speech/


Solution

  • This one just worked with me:

    from elevenlabs import generate, save
    
    audio = generate(
      text="Hi! My name is Bella, nice to meet you!",
      voice="Bella",
      model="eleven_monolingual_v1"
    )
    
    save(audio, "speech.mp3")
    

    You can add few lines to define your saving path:

    from elevenlabs import generate, save
    
    audio = generate(
      text="Hi! My name is Bella, nice to meet you!",
      voice="Bella",
      model="eleven_monolingual_v1"
    )
    
    Folderpath_main=os.getcwd()
    FileName = "speech.mp3"
    Saving_path = os.path.join(Folderpath_main, FileName) ## or simply define your path 
    save(audio, Saving_path)