Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions text_to_speech.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import pyttsx3

engine =pyttsx3.init()
voices= engine.getProperty("voices")
for i in voices:
print(i.id)
print(i.name)

id ="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0"
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Missing space before assignment operator. Should be 'voices = engine.getProperty("voices")' for consistent formatting.

Suggested change
engine =pyttsx3.init()
voices= engine.getProperty("voices")
for i in voices:
print(i.id)
print(i.name)
id ="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0"
engine = pyttsx3.init()
voices = engine.getProperty("voices")
for i in voices:
print(i.id)
print(i.name)
id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0"

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Missing space after assignment operator. Should be 'id = "HKEY_LOCAL_MACHINE...' for consistent formatting.

Suggested change
id ="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0"
id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0"

Copilot uses AI. Check for mistakes.
engine.setProperty(i, id)
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded Windows-specific voice ID makes the code non-portable. Consider selecting a voice from the available voices list or adding platform detection.

Suggested change
id ="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0"
engine.setProperty(i, id)
# Dynamically select a voice based on desired attributes (e.g., language or name)
selected_voice = None
for voice in voices:
if "en_US" in voice.id or "English" in voice.name: # Example condition for English voices
selected_voice = voice.id
break
if selected_voice:
engine.setProperty("voice", selected_voice)
else:
print("No matching voice found. Using the default voice.")

Copilot uses AI. Check for mistakes.
engine.setProperty("rate",176)
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using undefined variable 'i' from the previous loop. The loop variable 'i' is out of scope here. Should use 'voice' property name like 'voice' instead.

Suggested change
for i in voices:
print(i.id)
print(i.name)
id ="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0"
engine.setProperty(i, id)
engine.setProperty("rate",176)
for voice in voices:
print(voice.id)
print(voice.name)
desired_voice_id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0"
engine.setProperty("voice", desired_voice_id)
engine.setProperty("rate", 176)

Copilot uses AI. Check for mistakes.
Copy link

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic number 176 for speech rate should be defined as a named constant or documented with a comment explaining the chosen value.

Suggested change
engine.setProperty("rate",176)
engine.setProperty("rate", DEFAULT_SPEECH_RATE)

Copilot uses AI. Check for mistakes.
engine.say("hello world")
engine.runAndWait()