- 1 year ago
powershell tts command narrator change using python
To change the text-to-speech (TTS) voice settings in Windows Narrator using Python, you can use the pyttsx3
library, which provides a simple interface to interact with the Windows TTS engine. First, make sure you have pyttsx3
installed:
bashpip install pyttsx3
Then, you can use the following Python code to change the TTS voice settings:
pythonimport pyttsx3
def set_narrator_voice(name):
# Initialize the TTS engine
engine = pyttsx3.init()
# Get the list of available voices
voices = engine.getProperty('voices')
# Find the voice with the specified name
selected_voice = None
for voice in voices:
if name.lower() in voice.name.lower():
selected_voice = voice
break
# If the specified voice is found, set it as the active voice
if selected_voice:
engine.setProperty('voice', selected_voice.id)
print(f"Voice changed to: {selected_voice.name}")
else:
print("Voice not found. No changes made.")
if __name__ == "__main__":
# Replace 'Microsoft Zira' with the desired voice name
set_narrator_voice('Microsoft Zira')
In this example, we use the pyttsx3
library to set the TTS voice to "Microsoft Zira." You can change the voice name to any other available voice on your system. To see the list of available voices and their names, you can modify the code to print the voice.name
for each voice in the voices
list.
Please note that the voices available depend on the installed TTS voices on your Windows system. If you want to install additional TTS voices, you can do so via the Windows Settings under the "Time & Language" -> "Speech" section.