@capacitor-community/text-to-speech 4.0.1 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -30,20 +30,6 @@ npm install @capacitor-community/text-to-speech
30
30
  npx cap sync
31
31
  ```
32
32
 
33
- ### Android
34
-
35
- According to the [Android documentation](https://developer.android.com/reference/android/speech/tts/TextToSpeech), apps targeting **Android 11** should declare [TextToSpeech.Engine.INTENT_ACTION_TTS_SERVICE](https://developer.android.com/reference/android/speech/tts/TextToSpeech.Engine#INTENT_ACTION_TTS_SERVICE) in the queries elements of their manifest:
36
-
37
- ```xml
38
- <queries>
39
- <intent>
40
- <action android:name="android.intent.action.TTS_SERVICE" />
41
- </intent>
42
- </queries>
43
- ```
44
-
45
- [Here](https://github.com/robingenz/capacitor-plugin-demo/commit/b7dc6c6d6652be9356d354df1faeb6a40e442797) you can find an example commit.
46
-
47
33
  ## Configuration
48
34
 
49
35
  No configuration required for this plugin.
@@ -95,6 +81,7 @@ const isLanguageSupported = async (lang: string) => {
95
81
  * [`getSupportedVoices()`](#getsupportedvoices)
96
82
  * [`isLanguageSupported(...)`](#islanguagesupported)
97
83
  * [`openInstall()`](#openinstall)
84
+ * [`addListener('onRangeStart', ...)`](#addlisteneronrangestart)
98
85
  * [Interfaces](#interfaces)
99
86
 
100
87
  </docgen-index>
@@ -184,6 +171,22 @@ Only available for Android.
184
171
  --------------------
185
172
 
186
173
 
174
+ ### addListener('onRangeStart', ...)
175
+
176
+ ```typescript
177
+ addListener(eventName: 'onRangeStart', listenerFunc: (info: { start: number; end: number; spokenWord: string; }) => void) => Promise<PluginListenerHandle>
178
+ ```
179
+
180
+ | Param | Type |
181
+ | ------------------ | ----------------------------------------------------------------------------------- |
182
+ | **`eventName`** | <code>'onRangeStart'</code> |
183
+ | **`listenerFunc`** | <code>(info: { start: number; end: number; spokenWord: string; }) =&gt; void</code> |
184
+
185
+ **Returns:** <code>Promise&lt;<a href="#pluginlistenerhandle">PluginListenerHandle</a>&gt;</code>
186
+
187
+ --------------------
188
+
189
+
187
190
  ### Interfaces
188
191
 
189
192
 
@@ -212,6 +215,13 @@ The <a href="#speechsynthesisvoice">SpeechSynthesisVoice</a> interface represent
212
215
  | **`name`** | <code>string</code> | Human-readable name that represents the voice. |
213
216
  | **`voiceURI`** | <code>string</code> | Type of URI and location of the speech synthesis service for this voice. |
214
217
 
218
+
219
+ #### PluginListenerHandle
220
+
221
+ | Prop | Type |
222
+ | ------------ | ----------------------------------------- |
223
+ | **`remove`** | <code>() =&gt; Promise&lt;void&gt;</code> |
224
+
215
225
  </docgen-api>
216
226
 
217
227
  ## Changelog
@@ -1,2 +1,7 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <queries>
3
+ <intent>
4
+ <action android:name="android.intent.action.TTS_SERVICE" />
5
+ </intent>
6
+ </queries>
2
7
  </manifest>
@@ -3,4 +3,5 @@ package com.getcapacitor.community.tts;
3
3
  public interface SpeakResultCallback {
4
4
  void onDone();
5
5
  void onError();
6
+ void onRangeStart(int start, int end, String spokenWord);
6
7
  }
@@ -13,7 +13,6 @@ import com.getcapacitor.JSArray;
13
13
  import com.getcapacitor.JSObject;
14
14
  import java.util.ArrayList;
15
15
  import java.util.Collections;
16
- import java.util.Comparator;
17
16
  import java.util.HashMap;
18
17
  import java.util.Locale;
19
18
  import java.util.Set;
@@ -66,6 +65,12 @@ public class TextToSpeech implements android.speech.tts.TextToSpeech.OnInitListe
66
65
  public void onError(String utteranceId) {
67
66
  resultCallback.onError();
68
67
  }
68
+
69
+ @Override
70
+ public void onRangeStart(String utteranceId, int start, int end, int frame) {
71
+ String spokenWord = text.substring(start, end);
72
+ resultCallback.onRangeStart(start, end, spokenWord);
73
+ }
69
74
  }
70
75
  );
71
76
 
@@ -116,6 +121,9 @@ public class TextToSpeech implements android.speech.tts.TextToSpeech.OnInitListe
116
121
  return result;
117
122
  }
118
123
 
124
+ /**
125
+ * @return Ordered list of voices. The order is guaranteed to remain the same as long as the voices in tts.getVoices() do not change.
126
+ */
119
127
  public ArrayList<Voice> getSupportedVoicesOrdered() {
120
128
  Set<Voice> supportedVoices = tts.getVoices();
121
129
  ArrayList<Voice> orderedVoices = new ArrayList<Voice>();
@@ -123,7 +131,8 @@ public class TextToSpeech implements android.speech.tts.TextToSpeech.OnInitListe
123
131
  orderedVoices.add(supportedVoice);
124
132
  }
125
133
 
126
- Collections.sort(orderedVoices, Comparator.comparing(Voice::hashCode));
134
+ //voice.getName() is guaranteed to be unique, so will be used for sorting.
135
+ Collections.sort(orderedVoices, (v1, v2) -> v1.getName().compareTo(v2.getName()));
127
136
 
128
137
  return orderedVoices;
129
138
  }
@@ -1,5 +1,6 @@
1
1
  package com.getcapacitor.community.tts;
2
2
 
3
+ import android.util.Base64;
3
4
  import com.getcapacitor.JSArray;
4
5
  import com.getcapacitor.JSObject;
5
6
  import com.getcapacitor.Plugin;
@@ -53,6 +54,15 @@ public class TextToSpeechPlugin extends Plugin {
53
54
  public void onError() {
54
55
  call.reject(ERROR_UTTERANCE);
55
56
  }
57
+
58
+ @Override
59
+ public void onRangeStart(int start, int end, String spokenWord) {
60
+ JSObject ret = new JSObject();
61
+ ret.put("start", start);
62
+ ret.put("end", end);
63
+ ret.put("spokenWord", spokenWord);
64
+ notifyListeners("onRangeStart", ret);
65
+ }
56
66
  };
57
67
 
58
68
  try {
package/dist/docs.json CHANGED
@@ -80,6 +80,29 @@
80
80
  "docs": "Verifies proper installation and availability of resource files on the system.\n\nOnly available for Android.",
81
81
  "complexTypes": [],
82
82
  "slug": "openinstall"
83
+ },
84
+ {
85
+ "name": "addListener",
86
+ "signature": "(eventName: 'onRangeStart', listenerFunc: (info: { start: number; end: number; spokenWord: string; }) => void) => Promise<PluginListenerHandle>",
87
+ "parameters": [
88
+ {
89
+ "name": "eventName",
90
+ "docs": "",
91
+ "type": "'onRangeStart'"
92
+ },
93
+ {
94
+ "name": "listenerFunc",
95
+ "docs": "",
96
+ "type": "(info: { start: number; end: number; spokenWord: string; }) => void"
97
+ }
98
+ ],
99
+ "returns": "Promise<PluginListenerHandle>",
100
+ "tags": [],
101
+ "docs": "",
102
+ "complexTypes": [
103
+ "PluginListenerHandle"
104
+ ],
105
+ "slug": "addlisteneronrangestart"
83
106
  }
84
107
  ],
85
108
  "properties": []
@@ -241,6 +264,22 @@
241
264
  "type": "string"
242
265
  }
243
266
  ]
267
+ },
268
+ {
269
+ "name": "PluginListenerHandle",
270
+ "slug": "pluginlistenerhandle",
271
+ "docs": "",
272
+ "tags": [],
273
+ "methods": [],
274
+ "properties": [
275
+ {
276
+ "name": "remove",
277
+ "tags": [],
278
+ "docs": "",
279
+ "complexTypes": [],
280
+ "type": "() => Promise<void>"
281
+ }
282
+ ]
244
283
  }
245
284
  ],
246
285
  "enums": [],
@@ -1,3 +1,4 @@
1
+ import type { PluginListenerHandle } from '@capacitor/core';
1
2
  export interface TextToSpeechPlugin {
2
3
  /**
3
4
  * Starts the TTS engine and plays the desired text.
@@ -33,6 +34,11 @@ export interface TextToSpeechPlugin {
33
34
  * Only available for Android.
34
35
  */
35
36
  openInstall(): Promise<void>;
37
+ addListener(eventName: 'onRangeStart', listenerFunc: (info: {
38
+ start: number;
39
+ end: number;
40
+ spokenWord: string;
41
+ }) => void): Promise<PluginListenerHandle>;
36
42
  }
37
43
  export interface TTSOptions {
38
44
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface TextToSpeechPlugin {\n /**\n * Starts the TTS engine and plays the desired text.\n */\n speak(options: TTSOptions): Promise<void>;\n /**\n * Stops the TTS engine.\n */\n stop(): Promise<void>;\n /**\n * Returns a list of supported BCP 47 language tags.\n */\n getSupportedLanguages(): Promise<{ languages: string[] }>;\n /**\n * Returns a list of supported voices.\n */\n getSupportedVoices(): Promise<{ voices: SpeechSynthesisVoice[] }>;\n /**\n * Checks if a specific BCP 47 language tag is supported.\n */\n isLanguageSupported(options: {\n lang: string;\n }): Promise<{ supported: boolean }>;\n /**\n * Verifies proper installation and availability of resource files on the system.\n *\n * Only available for Android.\n */\n openInstall(): Promise<void>;\n}\n\nexport interface TTSOptions {\n /**\n * The text that will be synthesised when the utterance is spoken.\n *\n * @example \"Hello world\"\n */\n text: string;\n /**\n * The language of the utterance.\n * Possible languages can be queried using `getSupportedLanguages`.\n *\n * @default \"en-US\"\n */\n lang?: string;\n /**\n * The speed at which the utterance will be spoken at.\n *\n * @default 1.0\n */\n rate?: number;\n /**\n * The pitch at which the utterance will be spoken at.\n *\n * @default 1.0\n */\n pitch?: number;\n /**\n * The volume that the utterance will be spoken at.\n *\n * @default 1.0\n */\n volume?: number;\n /**\n * The index of the selected voice that will be used to speak the utterance.\n * Possible voices can be queried using `getSupportedVoices`.\n */\n voice?: number;\n /**\n * Select the iOS Audio session category.\n * Possible values: `ambient` and `playback`.\n * Use `playback` to play audio even when the app is in the background.\n *\n * Only available for iOS.\n *\n * @default \"ambient\"\n */\n category?: string;\n}\n\n/**\n * The SpeechSynthesisVoice interface represents a voice that the system supports.\n */\nexport interface SpeechSynthesisVoice {\n /**\n * Specifies whether the voice is the default voice for the current app (`true`) or not (`false`).\n *\n * @example false\n */\n default: boolean;\n /**\n * BCP 47 language tag indicating the language of the voice.\n *\n * @example \"en-US\"\n */\n lang: string;\n /**\n * Specifies whether the voice is supplied by a local (`true`) or remote (`false`) speech synthesizer service.\n *\n * @example true\n */\n localService: boolean;\n /**\n * Human-readable name that represents the voice.\n *\n * @example \"Microsoft Zira Desktop - English (United States)\"\n */\n name: string;\n /**\n * Type of URI and location of the speech synthesis service for this voice.\n *\n * @example \"urn:moz-tts:sapi:Microsoft Zira Desktop - English (United States)?en-US\"\n */\n voiceURI: string;\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["import type { PluginListenerHandle } from '@capacitor/core';\n\nexport interface TextToSpeechPlugin {\n /**\n * Starts the TTS engine and plays the desired text.\n */\n speak(options: TTSOptions): Promise<void>;\n /**\n * Stops the TTS engine.\n */\n stop(): Promise<void>;\n /**\n * Returns a list of supported BCP 47 language tags.\n */\n getSupportedLanguages(): Promise<{ languages: string[] }>;\n /**\n * Returns a list of supported voices.\n */\n getSupportedVoices(): Promise<{ voices: SpeechSynthesisVoice[] }>;\n /**\n * Checks if a specific BCP 47 language tag is supported.\n */\n isLanguageSupported(options: {\n lang: string;\n }): Promise<{ supported: boolean }>;\n /**\n * Verifies proper installation and availability of resource files on the system.\n *\n * Only available for Android.\n */\n openInstall(): Promise<void>;\n\n addListener(\n eventName: 'onRangeStart',\n listenerFunc: (info: {\n start: number;\n end: number;\n spokenWord: string;\n }) => void,\n ): Promise<PluginListenerHandle>;\n}\n\nexport interface TTSOptions {\n /**\n * The text that will be synthesised when the utterance is spoken.\n *\n * @example \"Hello world\"\n */\n text: string;\n /**\n * The language of the utterance.\n * Possible languages can be queried using `getSupportedLanguages`.\n *\n * @default \"en-US\"\n */\n lang?: string;\n /**\n * The speed at which the utterance will be spoken at.\n *\n * @default 1.0\n */\n rate?: number;\n /**\n * The pitch at which the utterance will be spoken at.\n *\n * @default 1.0\n */\n pitch?: number;\n /**\n * The volume that the utterance will be spoken at.\n *\n * @default 1.0\n */\n volume?: number;\n /**\n * The index of the selected voice that will be used to speak the utterance.\n * Possible voices can be queried using `getSupportedVoices`.\n */\n voice?: number;\n /**\n * Select the iOS Audio session category.\n * Possible values: `ambient` and `playback`.\n * Use `playback` to play audio even when the app is in the background.\n *\n * Only available for iOS.\n *\n * @default \"ambient\"\n */\n category?: string;\n}\n\n/**\n * The SpeechSynthesisVoice interface represents a voice that the system supports.\n */\nexport interface SpeechSynthesisVoice {\n /**\n * Specifies whether the voice is the default voice for the current app (`true`) or not (`false`).\n *\n * @example false\n */\n default: boolean;\n /**\n * BCP 47 language tag indicating the language of the voice.\n *\n * @example \"en-US\"\n */\n lang: string;\n /**\n * Specifies whether the voice is supplied by a local (`true`) or remote (`false`) speech synthesizer service.\n *\n * @example true\n */\n localService: boolean;\n /**\n * Human-readable name that represents the voice.\n *\n * @example \"Microsoft Zira Desktop - English (United States)\"\n */\n name: string;\n /**\n * Type of URI and location of the speech synthesis service for this voice.\n *\n * @example \"urn:moz-tts:sapi:Microsoft Zira Desktop - English (United States)?en-US\"\n */\n voiceURI: string;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capacitor-community/text-to-speech",
3
- "version": "4.0.1",
3
+ "version": "4.1.0",
4
4
  "description": "Capacitor plugin for synthesizing speech from text.",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",
@@ -31,10 +31,10 @@
31
31
  "@capacitor/core": "6.0.0",
32
32
  "@capacitor/docgen": "0.2.0",
33
33
  "@capacitor/ios": "6.0.0",
34
- "@ionic/eslint-config": "0.3.0",
34
+ "@ionic/eslint-config": "^0.4.0",
35
35
  "@ionic/prettier-config": "1.0.1",
36
36
  "@ionic/swiftlint-config": "1.1.2",
37
- "eslint": "7.32.0",
37
+ "eslint": "^8.57.0",
38
38
  "prettier": "2.3.2",
39
39
  "prettier-plugin-java": "1.0.2",
40
40
  "rimraf": "3.0.2",