2017-03-20 16:38:14 -04:00
|
|
|
import { Injectable } from '@angular/core';
|
2017-04-27 00:36:12 -04:00
|
|
|
import { Plugin, Cordova, IonicNativePlugin } from '@ionic-native/core';
|
2016-08-15 23:29:51 +10:00
|
|
|
|
|
|
|
|
export interface TTSOptions {
|
|
|
|
|
/** text to speak */
|
|
|
|
|
text: string;
|
|
|
|
|
/** a string like 'en-US', 'zh-CN', etc */
|
|
|
|
|
locale?: string;
|
|
|
|
|
/** speed rate, 0 ~ 1 */
|
|
|
|
|
rate?: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-03-22 01:44:49 -04:00
|
|
|
* @name Text To Speech
|
2016-08-15 23:29:51 +10:00
|
|
|
* @description
|
|
|
|
|
* Text to Speech plugin
|
|
|
|
|
*
|
|
|
|
|
* @usage
|
|
|
|
|
* ```
|
2017-03-20 16:38:14 -04:00
|
|
|
* import { TextToSpeech } from '@ionic-native/text-to-speech';
|
2016-08-15 23:29:51 +10:00
|
|
|
*
|
2017-03-20 16:38:14 -04:00
|
|
|
* constructor(private tts: TextToSpeech) { }
|
|
|
|
|
*
|
|
|
|
|
* ...
|
|
|
|
|
*
|
|
|
|
|
* this.tts.speak('Hello World')
|
2016-08-15 23:29:51 +10:00
|
|
|
* .then(() => console.log('Success'))
|
|
|
|
|
* .catch((reason: any) => console.log(reason));
|
|
|
|
|
*
|
|
|
|
|
* ```
|
2016-12-06 09:52:39 -05:00
|
|
|
* @interfaces
|
|
|
|
|
* TTSOptions
|
2016-08-15 23:29:51 +10:00
|
|
|
*/
|
|
|
|
|
@Plugin({
|
2017-03-20 16:38:14 -04:00
|
|
|
pluginName: 'Text To Speech',
|
2016-08-15 23:29:51 +10:00
|
|
|
plugin: 'cordova-plugin-tts',
|
|
|
|
|
pluginRef: 'TTS',
|
|
|
|
|
repo: 'https://github.com/vilic/cordova-plugin-tts'
|
|
|
|
|
})
|
2017-03-20 16:38:14 -04:00
|
|
|
@Injectable()
|
2017-04-27 00:36:12 -04:00
|
|
|
export class TextToSpeech extends IonicNativePlugin {
|
2016-08-15 23:29:51 +10:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function speaks
|
|
|
|
|
* @param options {string | TTSOptions} Text to speak or TTSOptions
|
|
|
|
|
* @return {Promise<any>} Returns a promise that resolves when the speaking finishes
|
|
|
|
|
*/
|
|
|
|
|
@Cordova({
|
|
|
|
|
successIndex: 1,
|
|
|
|
|
errorIndex: 2
|
|
|
|
|
})
|
2017-03-20 16:38:14 -04:00
|
|
|
speak(options: string | TTSOptions): Promise<any> {
|
2016-08-15 23:29:51 +10:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-20 16:38:14 -04:00
|
|
|
/**
|
|
|
|
|
* Stop any current TTS playback
|
|
|
|
|
* @return {Promise<any>}
|
|
|
|
|
*/
|
|
|
|
|
@Cordova()
|
|
|
|
|
stop(): Promise<any> {
|
2017-03-02 04:01:39 +02:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-15 23:29:51 +10:00
|
|
|
}
|