Text to speech python with 100+ voices

This code uses the fakeyou library to generate a text-to-speech audio file and the winsound library to play the audio file on a Windows operating system. It creates an instance of the FakeYou class, gets a list of available voices, and generates an audio file using the specified text and voice model. The generated audio file is then played using the PlaySound() function.

Here is an explanation of each line of code in the provided script:

  • import fakeyou: This line imports the fakeyou library, which provides text-to-speech functionality.
  • import winsound: This line imports the winsound library, which provides functions for playing audio files on a Windows operating system.
  • fy = fakeyou.FakeYou(): This line creates an instance of the FakeYou class from the fakeyou library and assigns it to the variable fy.

  • voices = fy.list_voices(size=1): This line uses the list_voices() method of the FakeYou instance to get a list of available voices and assigns it to the variable voices. The size parameter specifies the maximum number of voices to return.

  • speak = "This is a message from codesempai": This line creates a string variable with the text that will be used to generate the audio file.

  • token, titles = next(zip(voices.modelTokens, voices.title)): This line uses the zip() function to combine the modelTokens and title attributes of the voices object and assigns the resulting tuple to the variables token and titles, respectively. The next() function is used to retrieve the first item in the iterator returned by zip().

  • fy.say(speak, ttsModelToken="TM:jc2esv5g5rfn", filename=titles + ".wav", cooldown=2): This line uses the say() method of the FakeYou instance to generate an audio file using the specified text, voice model, file name, and cooldown time. The speak variable specifies the text to be synthesized, the ttsModelToken parameter specifies the voice model to use, and the filename parameter specifies the name of the output file. The cooldown parameter specifies the number of seconds to wait between generating audio files.

  • print('file made'): This line prints a message to the console indicating that the audio file has been generated.
  • winsound.PlaySound('fakeyou.wav', winsound.SND_FILENAME): This line uses the PlaySound() function from the winsound library to play the audio file specified by the filename parameter.

</> CODE :

  1. import fakeyou
  2. import winsound

  3. fy = fakeyou.FakeYou()
  4. # defining the class

  5. voices = fy.list_voices(size=1)

  6. # for title, creator in zip(voices.title, voices.creatorUsername):
  7. # print(title, creator)

  8. speak = "this is a massage from codesempai"

  9. token, titles = next(zip(voices.modelTokens, voices.title))

  10. # getting token and titles
  11. # print(f'Model token: {token}')
  12. # print(f'Voice title: {titles}')

  13. fy.say(speak, ttsModelToken="TM:jc2esv5g5rfn", filename=titles + ".wav", cooldown=2)

  14. # fy.say(speak, ttsModelToken="TM:jc2esv5g5rfn", filename=titles + ".wav", cooldown=2)

  15. print('file made')
  16. winsound.PlaySound('fakeyou.wav', winsound.SND_FILENAME)

# You can  Change token 


# You can  Change token 

Execution time(21s) sucked!

so I came up with a different solution That is perfect for the natural text-to-speech function

Post a Comment

If you have any doubts, please let me know

Previous Post Next Post