Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ TTS.speak(speakOptions).then(

- `speak(options: SpeakOptions): Promise<any>` - start speaking with the given options
- `pause(): void` - pause the speech
- `stop(): void` - stop the speech
- `resume(): void` - resume the speech
- `destroy(): void` - release resources for the speech synthesizer/engine

Expand Down Expand Up @@ -104,6 +105,10 @@ let speakOptions: SpeakOptions = {

- `getAvailableLanguages(): Promise<Array<Language>>;` - returns an array of available languages (use to prevent using non-existing language/local codes)

### Android and iOS specific features

The `pause()` is only supported on iOS. Android stops the speech and will resume from the start. Also both `pause()` and `stop()` takes one argument on iOS, indicating whether we should stop right now (`true`) or after the word being said (`false`).

## Credits

Inspired by James Montemagno's [TextToSpeech Xamarin plugin](https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/TextToSpeech)
Expand Down
7 changes: 7 additions & 0 deletions src/texttospeech.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,20 @@ export class TNSTextToSpeech {
/**
* Interrupts the current utterance and discards other utterances in the queue.
* https://developer.android.com/reference/android/speech/tts/TextToSpeech.html#stop()
* Same as stop()
*/
public pause() {
if (this._tts && this._initialized) {
this._tts.stop();
}
}

public stop() {
if (this._tts && this._initialized) {
this._tts.stop();
}
}

public resume() {
// In Android there's no pause so we resume playng the last phrase...
if (this._lastOptions) {
Expand Down
6 changes: 6 additions & 0 deletions src/texttospeech.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@ export class TNSTextToSpeech {
);
}

public stop(now) {
this._speechSynthesizer.stopSpeakingAtBoundary(
now ? AVSpeechBoundary.Immediate : AVSpeechBoundary.Word
);
}

public resume() {
this._speechSynthesizer.continueSpeaking();
}
Expand Down