Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plugin): Text to Speech Advanced #3627

Merged
merged 5 commits into from
Apr 5, 2021
Merged
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
89 changes: 89 additions & 0 deletions src/@ionic-native/plugins/text-to-speech-advanced/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import { Injectable } from '@angular/core';
import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core';

export interface TTSOptions {
/** text to speak */
text: string;
/** cancel, boolean: true/false */
identifier: string;
/** voice identifier (iOS / Android) from getVoices */
locale?: string;
/** speed rate, 0 ~ 1 */
rate?: number;
/** pitch, 0 ~ 1 */
pitch?: number;
/** cancel, boolean: true/false */
cancel?: boolean;
}

export interface TTSVoice {
/** Voice name */
name: string;
/** Voice language */
language: string;
/** Voice identifier string */
identifier: string;
}

/**
* @name Text To Speech Advanced
* @description
* Text to Speech plugin
*
* @usage
* ```typescript
* import { TextToSpeechAdvanced } from '@ionic-native/text-to-speech-advanced/ngx';
*
* constructor(private tts: TextToSpeechAdvanced) { }
*
* ...
*
* this.tts.speak('Hello World')
* .then(() => console.log('Success'))
* .catch((reason: any) => console.log(reason));
*
* ```
* @interfaces
* TTSOptions
* TTSVoice
*/
@Plugin({
pluginName: 'Text To Speech Advanced',
plugin: 'cordova-plugin-tts-advanced',
pluginRef: 'TTS',
repo: 'https://github.com/spasma/cordova-plugin-tts-advanced',
platforms: ['Android', 'iOS'],
})
@Injectable()
export class TextToSpeechAdvanced extends IonicNativePlugin {
/**
* This function speaks
* @param textOrOptions {string | TTSOptions} Text to speak or TTSOptions
* @return {Promise<any>} Returns a promise that resolves when the speaking finishes
*/
@Cordova({
successIndex: 1,
errorIndex: 2,
})
speak(textOrOptions: string | TTSOptions): Promise<any> {
return;
}

/**
* Stop any current TTS playback
* @return {Promise<any>}
*/
@Cordova()
stop(): Promise<any> {
return;
}

/**
* Get all voices
* @return {Promise<TTSVoice[]>}
*/
@Cordova()
getVoices(): Promise<TTSVoice[]> {
return;
}
}