SpeechCore is a cross-platform Python wrapper for screen reader and text-to-speech functionality. It provides a unified interface for speech synthesis, voice control, and braille output across different operating systems. The library supports multiple speech drivers and includes Windows-specific SAPI (Speech API) functionality.
pip install speechcoreMain class for speech synthesis and screen reader functionality. Only one instance may exist at a time.
Context Manager Support: Can be used with with statement for automatic initialization and cleanup.
with SpeechCore() as speech:
speech.output("Hello, world!")Windows-only class providing direct access to Microsoft's Speech API (SAPI). Only available on Windows platforms.
Context Manager Support: Can be used with with statement for automatic initialization and cleanup.
# Windows only
with Sapi() as sapi:
sapi.speak("Hello from SAPI!")Initialize the SpeechCore library.
- Returns: None
- Raises:
InitializationErrorif initialization fails
Free resources and shutdown the library.
- Returns: None
Check if SpeechCore is currently loaded and initialized.
- Returns:
bool- True if loaded, False otherwise
Automatically detect and set the best available speech driver.
- Returns: None
Get the name of a speech driver by index.
- Parameters:
index(int): Driver index
- Returns:
str- Driver name
Get the name of the currently active speech driver.
- Returns:
str- Current driver name
Set the active speech driver by index.
- Parameters:
index(int): Driver index to activate
- Returns: None
Get the total number of available speech drivers.
- Returns:
int- Number of available drivers
Get the name of a voice by index.
- Parameters:
index(int): Voice index
- Returns:
str- Voice name
Get the name of the currently active voice.
- Returns:
str- Current voice name
Set the active voice by index.
- Parameters:
index(int): Voice index to activate
- Returns: None
Get the total number of available voices.
- Returns:
int- Number of available voices
Set the speech volume level.
- Parameters:
offset(float): Volume level (typically 0.0 to 1.0)
- Returns: None
Get the current speech volume level.
- Returns:
float- Current volume level
Set the speech rate (speed).
- Parameters:
offset(float): Speech rate value
- Returns: None
Get the current speech rate.
- Returns:
float- Current speech rate
Speak the given text.
- Parameters:
text(str): Text to speakinterrupt(bool): Whether to interrupt current speech (default: False)
- Returns:
bool- True if successful
Output text to braille display.
- Parameters:
text(str): Text to output to braille
- Returns:
bool- True if successful
Save speech output to an audio file.
- Parameters:
filename(str): Output file pathtext(str): Text to convert to audio
- Returns: None
Resume paused speech.
- Returns: None
Pause current speech.
- Returns: None
Stop current speech immediately.
- Returns: None
Check if speech is currently active.
- Returns:
bool- True if speaking, False otherwise
Get current speech system capability flags.
- Returns:
int- Bitfield of capability flags
Check if specific speech flags are set.
- Parameters:
flags(int): Flags to check
- Returns:
bool- True if flags are set
Initialize the SAPI interface.
- Returns: None
- Raises:
InitializationErrorif initialization fails - Raises:
NotImplementedErroron non-Windows platforms
Release SAPI resources.
- Returns: None
Check if SAPI is currently loaded.
- Returns:
bool- True if loaded, False otherwise
Set SAPI voice speech rate.
- Parameters:
offset(float): Speech rate value
- Returns: None
Get current SAPI voice speech rate.
- Returns:
float- Current speech rate
Set SAPI voice volume level.
- Parameters:
offset(float): Volume level
- Returns: None
Get current SAPI voice volume level.
- Returns:
float- Current volume level
Get SAPI voice name by index.
- Parameters:
index(int): Voice index
- Returns:
str- Voice name
Get current SAPI voice name.
- Returns:
str- Current voice name
Set SAPI voice by index.
- Parameters:
index(int): Voice index
- Returns: None
Set SAPI voice by name.
- Parameters:
voice_name(str): Name of voice to set
- Returns: None
Get number of available SAPI voices.
- Returns:
int- Number of voices
Speak text using SAPI.
- Parameters:
text(str): Text to speakinterrupt(bool): Whether to interrupt current speech (default: False)xml(bool): Whether text contains SSML markup (default: False)
- Returns: None
Save SAPI speech to audio file.
- Parameters:
filename(str): Output file pathtext(str): Text to convertxml(bool): Whether text contains SSML markup (default: False)
- Returns: None
Resume paused SAPI speech.
- Returns: None
Pause current SAPI speech.
- Returns: None
Stop current SAPI speech.
- Returns: None
Speech capability flags available from __speech_common:
SC_SPEECH_FLOW_CONTROL- Speech flow control supportSC_SPEECH_PARAMETER_CONTROL- Speech parameter control supportSC_VOICE_CONFIG- Voice configuration supportSC_FILE_OUTPUT- File output supportSC_HAS_SPEECH- Speech synthesis supportSC_HAS_BRAILLE- Braille output supportSC_HAS_SPEECH_STATE- Speech state monitoring support
Raised when SpeechCore or SAPI initialization fails.
Raised when attempting to use methods before proper initialization.
from speechcore import SpeechCore
# Basic usage with context manager
with SpeechCore() as speech:
speech.output("Hello, this is SpeechCore!")
# Check available voices
voice_count = speech.get_voices()
for i in range(voice_count):
print(f"Voice {i}: {speech.get_voice(i)}")
# Adjust speech parameters
speech.set_rate(0.5) # Slower speech
speech.set_volume(0.8) # Lower volume
speech.output("This is slower and quieter speech.")
# Windows-specific SAPI usage
if sys.platform == "win32":
from speechcore import Sapi
with Sapi() as sapi:
sapi.speak("Hello from Windows SAPI!")