From 1ac0b919816da48349005b1a07c9062f71d7c4c6 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Tue, 29 Dec 2020 19:25:56 -0600 Subject: [PATCH] Add ugly hack to prove that speech works. --- examples/android/src/lib.rs | 3 +++ src/backends/android.rs | 5 ++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/examples/android/src/lib.rs b/examples/android/src/lib.rs index 87014cc..da4ef23 100644 --- a/examples/android/src/lib.rs +++ b/examples/android/src/lib.rs @@ -1,7 +1,10 @@ +use std::thread; +use std::time::Duration; use tts::*; fn run() -> Result<(), Error> { let mut tts = TTS::default()?; + thread::sleep(Duration::from_secs(5)); let Features { utterance_callbacks, .. diff --git a/src/backends/android.rs b/src/backends/android.rs index 65fa756..6a2e200 100644 --- a/src/backends/android.rs +++ b/src/backends/android.rs @@ -2,7 +2,6 @@ use std::sync::Mutex; use jni::objects::{GlobalRef, JObject}; -use jni::JNIEnv; use jni::JavaVM; use lazy_static::lazy_static; use log::info; @@ -27,7 +26,7 @@ impl Android { *backend_id += 1; let native_activity = ndk_glue::native_activity(); let vm = Self::vm()?; - let env = vm.attach_current_thread()?; + let env = vm.attach_current_thread_permanently()?; let tts = env.new_object( "android/speech/tts/TextToSpeech", "(Landroid/content/Context;Landroid/speech/tts/TextToSpeech$OnInitListener;)V", @@ -69,7 +68,7 @@ impl Backend for Android { println!("Speaking {}, {:?}", text, interrupt); let vm = Self::vm()?; println!("Retrieved"); - let env = vm.attach_current_thread()?; + let env = vm.get_env()?; println!("attached"); let tts = self.tts.as_obj(); let text = env.new_string(text)?;