From ca190db829ae125d2da6d79e2c8673d5c7f5da9d Mon Sep 17 00:00:00 2001 From: Sebastiaan Pasma Date: Mon, 5 Apr 2021 23:30:28 +0200 Subject: [PATCH] feat(plugin): Text to Speech Advanced (#3627) * Text to speech advanced plugin * Add @interface * docs update * jsdoc fix * jsdoc fix --- .../plugins/text-to-speech-advanced/index.ts | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/@ionic-native/plugins/text-to-speech-advanced/index.ts diff --git a/src/@ionic-native/plugins/text-to-speech-advanced/index.ts b/src/@ionic-native/plugins/text-to-speech-advanced/index.ts new file mode 100644 index 000000000..c021b8acf --- /dev/null +++ b/src/@ionic-native/plugins/text-to-speech-advanced/index.ts @@ -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} Returns a promise that resolves when the speaking finishes + */ + @Cordova({ + successIndex: 1, + errorIndex: 2, + }) + speak(textOrOptions: string | TTSOptions): Promise { + return; + } + + /** + * Stop any current TTS playback + * @return {Promise} + */ + @Cordova() + stop(): Promise { + return; + } + + /** + * Get all voices + * @return {Promise} + */ + @Cordova() + getVoices(): Promise { + return; + } +}