To convert 'text-to-speech' we're using the pyttsx3 library in this kit. We can also change the voice of the computer to another voice. This module provides two different types of voices one is male and another one is female.
In our pyttsx3-dependent library, we're getting the voices by running a python file. The 'voiceChange()' function is invoked and an instance is initialized of the module. In this voice library, using the 'setProperty()' method and we get the available voices and we can change the user's voice ID accordingly to bring a male or female voice. If we set the speed rate of pyttsx3 below 200, the voice will speak slowly and if we set it above 200, it will increase the rate of the engine.
To change the voice of the pyttsx3 computer,
- we'll have to get the list of objects of voices.
- In the pyttsx3 package, we used 'getProperty()' to take a string as a parameter and return an object matching.
There are some APIs available to convert text to speech in python. Python Text to Speech API commonly known as the pyttsx3 API is one of them. pyttsx3 is a very easy-to-use tool that is used to convert the text entered into audio. We can also change the default language to your favorite language. For that, you should need to install additional languages to change the default language of your choice. After installing the languages, you can get the list of available voices from voices properties on your computer and then you can choose your language from the list.
Here is an example of how you can change the voice in pyttsx3 in Python,
Fig : Preview of the output that you will get on running this code from your IDE.
Code
In this solution we're using PyAudio and pyttsx3 libraries.
Instructions
Follow the steps carefully to get the output easily.
- Install PyAudio and pyttsx3 on your IDE(Any of your favorite IDE).
- Open terminal and install the above mentioned libraries using the command given in 3 & 4 steps.
- PyAudio - pip install PyAudio.
- pyttsx3 - pip install pyttsx3.
- Copy the snippet using the 'copy' and paste it in your IDE.
- Run the file to generate the output.
I hope you found this useful. I have added the link to dependent libraries, version information in the following sections.
I found this code snippet by searching for 'How to change the voice in pyttsx3' in kandi. You can try any such use case!
Environment Tested
I tested this solution in the following versions. Be mindful of changes when working with other versions.
- The solution is created in PyCharm 2021.3.
- The solution is tested on Python 3.9.7.
- PyAudio version-0.2.13.
- pyttsx3version-2.90.
Using this solution, we are able to change the voice in pyttsx3 with simple steps. This process also facilities an easy way to use, hassle-free method to create a hands-on working version of code which would help us to change the voice in pyttsx3.
Dependent Libraries
pyttsx3by nateshmbhat
Offline Text To Speech synthesis for python
pyttsx3by nateshmbhat
Python 1571 Version:v.2.90 License: Weak Copyleft (MPL-2.0)
You can also search for any dependent libraries on kandi like 'PyAudio' and 'pyttsx3'.
Support
- For any support on kandi solution kits, please use the chat
- For further learning resources, visit the Open Weaver Community learning page.