Lyrebird is a neat little website that lets you create a custom text to speech voice with one minute of your own recordings. This is pretty cool on its own, but lately I've been thinking about one way I could make it cooler: being able to generate audio from Lyrebird with an arbitrary sentence using a Python program. Lyrebird says on its website that it has a vocal avatar API, but it will be ready "very soon" (which, if you haven't noticed, is not now). This kinda bums me out, but I've reverse-engineered the basic functions of an API once, so I've decided to do it again.

My result was this Python script. (Windows only, sorry.)

Code:
import json, requests, winsound

def speak(text, userID, playSound=True, saveToFile=False, filename="test.wav"):
   r = requests.request(
      method="post",
      url="https://beta.myvoice.lyrebird.ai/api/v0/voice/generate",
      data=json.dumps({"text": text}),
      headers={"authorization": "Bearer "+userID}
   )
   
   wavdata = r.content
      
   if saveToFile:
      with open(filename, "wb") as f:
         f.write(wavdata)
   
   if playSound:
      winsound.PlaySound(wavdata,winsound.SND_MEMORY)

USER_ID = "put user id here"

# To convert and play audio, call speak() with the text as the first argument, and USER_ID as the second.
speak("Hello, World!", USER_ID)
# You can also set these parameters:
# playSound: True if sound is to be played, otherwise False
# saveToFile: True if converted audio is to be saved to a file, otherwise False
# filename: Filename to save to as a string
speak("This has been saved to a file on your computer.", USER_ID, playSound=False, saveToFile=True, filename="playMe.wav")

USER_ID is (as far as I can tell) a unique string for every Lyrebird account. In order to get this string, go to this page, go into the developer console, and type localStorage.token. Your USER_ID is the result of this.

I'd give you my USER_ID so you can test it out immediately, but then I'd have no way of knowing whether or not my voice was being used for nefarious purposes, so I'm asking any of you who are curious enough to try this out to make a Lyrebird account for yourselves to try this.

I tested this out by taking the Bee Movie script and converting it line by line (the only thing preventing me from converting it all at once is the 250-character limit). Here is the glorious YouTube upload:

https://www.youtube.com/watch?v=0iRjHfi8ZVU
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement