Skip to content

Commit

Permalink
feat: add onRangeStart listener (#132)
Browse files Browse the repository at this point in the history
* "Added RangeCount() method to get index & string of spoken word."

* "Resolved Prettier issues"
  • Loading branch information
Dhruv-1105 authored Jul 17, 2024
1 parent a838850 commit d6681a6
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
public interface SpeakResultCallback {
void onDone();
void onError();
void onRangeStart(int start, int end, String spokenWord);
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ public void onDone(String utteranceId) {
public void onError(String utteranceId) {
resultCallback.onError();
}

@Override
public void onRangeStart(String utteranceId, int start, int end, int frame) {
String spokenWord = text.substring(start, end);
resultCallback.onRangeStart(start, end, spokenWord);
}
}
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.getcapacitor.community.tts;

import android.util.Base64;
import com.getcapacitor.JSArray;
import com.getcapacitor.JSObject;
import com.getcapacitor.Plugin;
Expand Down Expand Up @@ -53,6 +54,15 @@ public void onDone() {
public void onError() {
call.reject(ERROR_UTTERANCE);
}

@Override
public void onRangeStart(int start, int end, String spokenWord) {
JSObject ret = new JSObject();
ret.put("start", start);
ret.put("end", end);
ret.put("spokenWord", spokenWord);
notifyListeners("onRangeStart", ret);
}
};

try {
Expand Down
11 changes: 11 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { PluginListenerHandle } from '@capacitor/core';

export interface TextToSpeechPlugin {
/**
* Starts the TTS engine and plays the desired text.
Expand Down Expand Up @@ -27,6 +29,15 @@ export interface TextToSpeechPlugin {
* Only available for Android.
*/
openInstall(): Promise<void>;

addListener(
eventName: 'onRangeStart',
listenerFunc: (info: {
start: number;
end: number;
spokenWord: string;
}) => void,
): Promise<PluginListenerHandle>;
}

export interface TTSOptions {
Expand Down

0 comments on commit d6681a6

Please sign in to comment.