new TextToSpeechPlayer( [options])
Creates a new TextToSpeechPlayer instance
Parameters:
Name | Type | Argument | Description |
---|---|---|---|
options |
TextToSpeechOptions |
<optional> |
Configuration options |
- Source:
Example
```javascript const tts = new TextToSpeechPlayer({ language: 'en-US', rate: 1.2, volume: 0.8, cleanText: true }); ```
Methods
-
activate()
-
Activates the TextToSpeechPlayer.
- Source:
-
<async> initialize()
-
Initializes the player by loading voices and checking capabilities
- Source:
Throws:
-
If voice loading fails or no suitable voices found
Initialization steps:
- Loads available voices
- Selects appropriate voice
- Checks offline capability
- Sets up page listeners
- Type
- Error
Returns:
- Type
- Promise.<void>
-
mute(enable)
-
Mutes or unmutes audio output
Parameters:
Name Type Description enable
boolean True to mute, false to unmute
- Source:
Example
```javascript // Mute audio tts.mute(true); // Restore previous volume tts.mute(false); ```
-
pauseSpeaking(enable)
-
Pauses or resumes speech synthesis
Parameters:
Name Type Description enable
boolean True to pause, false to resume
- Source:
Example
```javascript // Pause speech tts.pauseSpeaking(true); // Resume speech tts.pauseSpeaking(false); ```
-
<async> speakText(text)
-
Speaks the provided text
Parameters:
Name Type Description text
string Text to be spoken
- Source:
Throws:
-
If speech synthesis fails or times out
Processing steps:
- Cancels any ongoing speech
- Cleans input text if enabled
- Creates utterance with current settings
- Handles speech synthesis
- Manages timeouts and Chrome workarounds
- Type
- Error
Returns:
- Type
- Promise.<void>
Example
```javascript await tts.speakText("Hello, world!"); ```
-
stopSpeaking()
-
Stops current speech synthesis Cleans up resources and resets state
- Source: