|
| 1 | +import { Injectable } from '@angular/core'; |
| 2 | +import { Cordova, IonicNativePlugin, Plugin } from '@ionic-native/core'; |
| 3 | + |
| 4 | +export interface TTSOptions { |
| 5 | + /** text to speak */ |
| 6 | + text: string; |
| 7 | + /** cancel, boolean: true/false */ |
| 8 | + identifier: string; |
| 9 | + /** voice identifier (iOS / Android) from getVoices */ |
| 10 | + locale?: string; |
| 11 | + /** speed rate, 0 ~ 1 */ |
| 12 | + rate?: number; |
| 13 | + /** pitch, 0 ~ 1 */ |
| 14 | + pitch?: number; |
| 15 | + /** cancel, boolean: true/false */ |
| 16 | + cancel?: boolean; |
| 17 | +} |
| 18 | + |
| 19 | +export interface TTSVoice { |
| 20 | + /** Voice name */ |
| 21 | + name: string; |
| 22 | + /** Voice language */ |
| 23 | + language: string; |
| 24 | + /** Voice identifier string */ |
| 25 | + identifier: string; |
| 26 | +} |
| 27 | + |
| 28 | +/** |
| 29 | + * @name Text To Speech Advanced |
| 30 | + * @description |
| 31 | + * Text to Speech plugin |
| 32 | + * |
| 33 | + * @usage |
| 34 | + * ```typescript |
| 35 | + * import { TextToSpeechAdvanced } from '@ionic-native/text-to-speech-advanced/ngx'; |
| 36 | + * |
| 37 | + * constructor(private tts: TextToSpeechAdvanced) { } |
| 38 | + * |
| 39 | + * ... |
| 40 | + * |
| 41 | + * this.tts.speak('Hello World') |
| 42 | + * .then(() => console.log('Success')) |
| 43 | + * .catch((reason: any) => console.log(reason)); |
| 44 | + * |
| 45 | + * ``` |
| 46 | + * @interfaces |
| 47 | + * TTSOptions |
| 48 | + * TTSVoice |
| 49 | + */ |
| 50 | +@Plugin({ |
| 51 | + pluginName: 'Text To Speech Advanced', |
| 52 | + plugin: 'cordova-plugin-tts-advanced', |
| 53 | + pluginRef: 'TTS', |
| 54 | + repo: 'https://github.com/spasma/cordova-plugin-tts-advanced', |
| 55 | + platforms: ['Android', 'iOS'], |
| 56 | +}) |
| 57 | +@Injectable() |
| 58 | +export class TextToSpeechAdvanced extends IonicNativePlugin { |
| 59 | + /** |
| 60 | + * This function speaks |
| 61 | + * @param textOrOptions {string | TTSOptions} Text to speak or TTSOptions |
| 62 | + * @return {Promise<any>} Returns a promise that resolves when the speaking finishes |
| 63 | + */ |
| 64 | + @Cordova({ |
| 65 | + successIndex: 1, |
| 66 | + errorIndex: 2, |
| 67 | + }) |
| 68 | + speak(textOrOptions: string | TTSOptions): Promise<any> { |
| 69 | + return; |
| 70 | + } |
| 71 | + |
| 72 | + /** |
| 73 | + * Stop any current TTS playback |
| 74 | + * @return {Promise<any>} |
| 75 | + */ |
| 76 | + @Cordova() |
| 77 | + stop(): Promise<any> { |
| 78 | + return; |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Get all voices |
| 83 | + * @return {Promise<TTSVoice[]>} |
| 84 | + */ |
| 85 | + @Cordova() |
| 86 | + getVoices(): Promise<TTSVoice[]> { |
| 87 | + return; |
| 88 | + } |
| 89 | +} |
0 commit comments