Skip to content
This repository was archived by the owner on May 6, 2022. It is now read-only.

Commit f90be77

Browse files
authored
fix(android): add proxies for real playback listeners (#90)
1 parent 1fbf746 commit f90be77

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ dependencies {
126126
// noinspection GradleDynamicVersion
127127
implementation 'com.facebook.react:react-native:+'
128128
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinx_version"
129-
api 'io.spokestack:spokestack-android:10.0.0'
129+
api 'io.spokestack:spokestack-android:11.0.0'
130130

131131
// for TensorFlow Lite-powered wakeword detection and/or NLU
132132
implementation 'org.tensorflow:tensorflow-lite:2.3.0'

android/src/main/java/com/reactnativespokestack/SpokestackAdapter.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,19 @@ class SpokestackAdapter(sendFunc:(event: String, data: WritableMap) -> Unit):io.
5555
reactEvent.putString("url", event.ttsResponse.audioUri.toString())
5656
sendEvent("synthesize", reactEvent)
5757
}
58-
TTSEvent.Type.PLAYBACK_COMPLETE -> {
58+
TTSEvent.Type.PLAYBACK_STARTED -> {
59+
reactEvent.putBoolean("playing", true)
60+
sendEvent("play", reactEvent)
61+
}
62+
TTSEvent.Type.PLAYBACK_STOPPED -> {
5963
reactEvent.putBoolean("playing", false)
6064
sendEvent("play", reactEvent)
6165
}
66+
TTSEvent.Type.PLAYBACK_COMPLETE -> {
67+
// Playback is not pause-able in iOS
68+
// so this event does not exist there.
69+
Log.d(logTag, "Playback has completed")
70+
}
6271
TTSEvent.Type.ERROR -> {
6372
reactEvent.putString("error", "TTS error: " + event.error.localizedMessage)
6473
sendEvent("error", reactEvent)

android/src/main/java/com/reactnativespokestack/SpokestackModule.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,6 @@ class SpokestackModule(private val reactContext: ReactApplicationContext): React
331331
val response = AudioResponse(uri)
332332
audioPlayer.audioReceived(response)
333333

334-
/* TODO: Change this to a playback started listener when spokestack-android supports it. */
335-
val reactEvent = Arguments.createMap()
336-
reactEvent.putBoolean("playing", true)
337-
sendEvent("play", reactEvent)
338-
339334
// Resolve RN promise
340335
promise.resolve(null)
341336
promises.remove(SpokestackPromise.SPEAK)

example/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import React from 'react'
88
import checkPermission from './checkPermission'
99

1010
const noTranscriptMessage =
11-
'Press the listening button and speak to record a message for speech playback'
11+
'Press the "Listen" button and speak to record a message for speech playback'
1212

1313
export default function App() {
1414
const [listening, setListening] = React.useState(false)

0 commit comments

Comments
 (0)