Skip to main content

Python wrapper for the SpeechCore library (pybind11)

Project description

SpeechCore API Documentation

Overview

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.

Installation

pip install speechcore

Classes

SpeechCore

Main 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!")

Sapi

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!")

SpeechCore Methods

Initialization and Management

SpeechCore.init()

Initialize the SpeechCore library.

  • Returns: None
  • Raises: InitializationError if initialization fails

SpeechCore.free()

Free resources and shutdown the library.

  • Returns: None

SpeechCore.is_loaded() -> bool

Check if SpeechCore is currently loaded and initialized.

  • Returns: bool - True if loaded, False otherwise

Driver Management

detect_driver() -> None

Automatically detect and set the best available speech driver.

  • Returns: None

get_driver(index: int) -> str

Get the name of a speech driver by index.

  • Parameters:
    • index (int): Driver index
  • Returns: str - Driver name

current_driver() -> str

Get the name of the currently active speech driver.

  • Returns: str - Current driver name

set_driver(index: int) -> None

Set the active speech driver by index.

  • Parameters:
    • index (int): Driver index to activate
  • Returns: None

get_drivers() -> int

Get the total number of available speech drivers.

  • Returns: int - Number of available drivers

Voice Management

get_voice(index: int) -> str

Get the name of a voice by index.

  • Parameters:
    • index (int): Voice index
  • Returns: str - Voice name

get_current_voice() -> str

Get the name of the currently active voice.

  • Returns: str - Current voice name

set_voice(index: int) -> None

Set the active voice by index.

  • Parameters:
    • index (int): Voice index to activate
  • Returns: None

get_voices() -> int

Get the total number of available voices.

  • Returns: int - Number of available voices

Audio Control

set_volume(offset: float) -> None

Set the speech volume level.

  • Parameters:
    • offset (float): Volume level (typically 0.0 to 1.0)
  • Returns: None

get_volume() -> float

Get the current speech volume level.

  • Returns: float - Current volume level

set_rate(offset: float) -> None

Set the speech rate (speed).

  • Parameters:
    • offset (float): Speech rate value
  • Returns: None

get_rate() -> float

Get the current speech rate.

  • Returns: float - Current speech rate

Speech Output

output(text: str, interrupt: bool = False) -> bool

Speak the given text.

  • Parameters:
    • text (str): Text to speak
    • interrupt (bool): Whether to interrupt current speech (default: False)
  • Returns: bool - True if successful

output_braille(text: str) -> bool

Output text to braille display.

  • Parameters:
    • text (str): Text to output to braille
  • Returns: bool - True if successful

output_file(filename: str, text: str) -> None

Save speech output to an audio file.

  • Parameters:
    • filename (str): Output file path
    • text (str): Text to convert to audio
  • Returns: None

Playback Control

resume() -> None

Resume paused speech.

  • Returns: None

pause() -> None

Pause current speech.

  • Returns: None

stop() -> None

Stop current speech immediately.

  • Returns: None

is_speaking() -> bool

Check if speech is currently active.

  • Returns: bool - True if speaking, False otherwise

System Information

get_speech_flags() -> int

Get current speech system capability flags.

  • Returns: int - Bitfield of capability flags

check_speech_flags(flags: int) -> bool

Check if specific speech flags are set.

  • Parameters:
    • flags (int): Flags to check
  • Returns: bool - True if flags are set

Sapi Methods (Windows Only)

Initialization

Sapi.init()

Initialize the SAPI interface.

  • Returns: None
  • Raises: InitializationError if initialization fails
  • Raises: NotImplementedError on non-Windows platforms

Sapi.release()

Release SAPI resources.

  • Returns: None

Sapi.sapi_loaded() -> bool

Check if SAPI is currently loaded.

  • Returns: bool - True if loaded, False otherwise

Voice Control

voice_set_rate(offset: float) -> None

Set SAPI voice speech rate.

  • Parameters:
    • offset (float): Speech rate value
  • Returns: None

voice_get_rate() -> float

Get current SAPI voice speech rate.

  • Returns: float - Current speech rate

voice_set_volume(offset: float) -> None

Set SAPI voice volume level.

  • Parameters:
    • offset (float): Volume level
  • Returns: None

voice_get_volume() -> float

Get current SAPI voice volume level.

  • Returns: float - Current volume level

get_voice(index: int) -> str

Get SAPI voice name by index.

  • Parameters:
    • index (int): Voice index
  • Returns: str - Voice name

get_current_voice() -> str

Get current SAPI voice name.

  • Returns: str - Current voice name

set_voice_by_index(index: int) -> None

Set SAPI voice by index.

  • Parameters:
    • index (int): Voice index
  • Returns: None

set_voice(voice_name: str) -> None

Set SAPI voice by name.

  • Parameters:
    • voice_name (str): Name of voice to set
  • Returns: None

get_voices() -> int

Get number of available SAPI voices.

  • Returns: int - Number of voices

SAPI Speech Output

speak(text: str, interrupt: bool = False, xml: bool = False) -> None

Speak text using SAPI.

  • Parameters:
    • text (str): Text to speak
    • interrupt (bool): Whether to interrupt current speech (default: False)
    • xml (bool): Whether text contains SSML markup (default: False)
  • Returns: None

output_file(filename: str, text: str, xml: bool = False) -> None

Save SAPI speech to audio file.

  • Parameters:
    • filename (str): Output file path
    • text (str): Text to convert
    • xml (bool): Whether text contains SSML markup (default: False)
  • Returns: None

SAPI Playback Control

resume() -> None

Resume paused SAPI speech.

  • Returns: None

pause() -> None

Pause current SAPI speech.

  • Returns: None

stop() -> None

Stop current SAPI speech.

  • Returns: None

Constants

Speech capability flags available from __speech_common:

  • SC_SPEECH_FLOW_CONTROL - Speech flow control support
  • SC_SPEECH_PARAMETER_CONTROL - Speech parameter control support
  • SC_VOICE_CONFIG - Voice configuration support
  • SC_FILE_OUTPUT - File output support
  • SC_HAS_SPEECH - Speech synthesis support
  • SC_HAS_BRAILLE - Braille output support
  • SC_HAS_SPEECH_STATE - Speech state monitoring support

Exceptions

InitializationError

Raised when SpeechCore or SAPI initialization fails.

NotLoadedError

Raised when attempting to use methods before proper initialization.

Example Usage

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!")

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

speechcore-1.1.1-cp313-cp313-win_amd64.whl (715.5 kB view details)

Uploaded CPython 3.13Windows x86-64

speechcore-1.1.1-cp312-cp312-win_amd64.whl (715.4 kB view details)

Uploaded CPython 3.12Windows x86-64

speechcore-1.1.1-cp311-cp311-win_amd64.whl (714.4 kB view details)

Uploaded CPython 3.11Windows x86-64

speechcore-1.1.1-cp310-cp310-win_amd64.whl (713.0 kB view details)

Uploaded CPython 3.10Windows x86-64

speechcore-1.1.1-cp39-cp39-win_amd64.whl (715.4 kB view details)

Uploaded CPython 3.9Windows x86-64

speechcore-1.1.1-cp38-cp38-win_amd64.whl (713.1 kB view details)

Uploaded CPython 3.8Windows x86-64

File details

Details for the file speechcore-1.1.1-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: speechcore-1.1.1-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 715.5 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for speechcore-1.1.1-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 b813002990b8a4cbd27b3cdd99caf36ce2d3c22ee1330ca4b8b724889d0a7657
MD5 687747032420aca0d8d0d9b82cffa7ed
BLAKE2b-256 872d597bbfdbab2b168d3edd5383c8d514a41be02db77f9e6d4e3ba5af7da5e6

See more details on using hashes here.

File details

Details for the file speechcore-1.1.1-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: speechcore-1.1.1-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 715.4 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for speechcore-1.1.1-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 5cd4c821f2da875ec916e8e269fca85171eedc44799f56c287601260a84c90f0
MD5 6f4f21f29a9f76ef761f501709a2fac6
BLAKE2b-256 0f916b7a4ae61f9cfbe0709cab2ef0370909ec4071b58bcb7c4cc4abf2ab7ee6

See more details on using hashes here.

File details

Details for the file speechcore-1.1.1-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: speechcore-1.1.1-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 714.4 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for speechcore-1.1.1-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 32a738d45f0a2f8a04e73f980801741080341e2a7701b58d83d7b721c5d06997
MD5 48fd77dcc109f65e6b197336f65cf3c5
BLAKE2b-256 e39f33f8a81e816ff11165e1c353e89d113b654a46f6a33eedbefd59a31cb7cf

See more details on using hashes here.

File details

Details for the file speechcore-1.1.1-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: speechcore-1.1.1-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 713.0 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for speechcore-1.1.1-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 06a10ed99ff3977e3e9a9cf76b85996259fed39861bb0fa0d98abe6c840a805c
MD5 19ec5e2484242c367291f9e583de442b
BLAKE2b-256 3730689ea1c0ddaee691992ae94001cae283b28255246f9cf9ef1515871eefa3

See more details on using hashes here.

File details

Details for the file speechcore-1.1.1-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: speechcore-1.1.1-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 715.4 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for speechcore-1.1.1-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 132e19bbc92f483792202225bf9d147804740f70ca5af26ef12ff775dde352af
MD5 ffe1f9264b03aa70f593a4aba927b49d
BLAKE2b-256 e6bfa1766f060cf2e57f0af691e7dc9330c7f6d2214e3d162e52cba73fe002d5

See more details on using hashes here.

File details

Details for the file speechcore-1.1.1-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: speechcore-1.1.1-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 713.1 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for speechcore-1.1.1-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 0c9f9b4639725de4b28c563e440e4f685fd3a52df9e62c338ead541f4ce423b9
MD5 986d6dd1f821f75f1ddadd5ba959bd33
BLAKE2b-256 9ff6fd8900c2249221f22bceabb79455adcd9c8bec8c5515fc6d3937d2f07975

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page