use crate::{
JObjNew, JObjRef, JProxy, JType, Result,
android::{content::Context, os::Bundle},
java::lang::CharSequence,
java_class, java_constructor, java_implement, java_interface, java_method,
};
use std::sync::Arc;
#[java_class(name = "android/speech/tts/TextToSpeech")]
pub struct TextToSpeech;
impl TextToSpeech {
pub const ACTION_TTS_QUEUE_PROCESSING_COMPLETED: &'static str =
"android.speech.tts.TTS_QUEUE_PROCESSING_COMPLETED";
pub const ERROR: i32 = -1;
pub const ERROR_INVALID_REQUEST: i32 = -8;
pub const ERROR_NETWORK: i32 = -6;
pub const ERROR_NETWORK_TIMEOUT: i32 = -7;
pub const ERROR_NOT_INSTALLED_YET: i32 = -9;
pub const ERROR_OUTPUT: i32 = -5;
pub const ERROR_SYNTHESIS: i32 = -3;
pub const LANG_AVAILABLE: i32 = 0;
pub const LANG_COUNTRY_AVAILABLE: i32 = 1;
pub const LANG_COUNTRY_VAR_AVAILABLE: i32 = 2;
pub const LANG_MISSING_DATA: i32 = -1;
pub const LANG_NOT_SUPPORTED: i32 = -2;
pub const QUEUE_ADD: i32 = 1;
pub const QUEUE_DESTROY: i32 = 2;
pub const QUEUE_FLUSH: i32 = 0;
pub const STOPPED: i32 = -2;
pub const SUCCESS: i32 = 0;
pub const ERROR_SERVICE: i32 = -4;
#[java_constructor]
pub fn new<L: TextToSpeech_OnInitListener>(context: &Context, listener: &L) -> Self {}
#[java_method]
pub fn stop(&self) -> i32 {}
#[java_method]
pub fn is_speaking(&self) -> bool {}
#[java_method]
pub fn shutdown(&self) {}
#[java_method]
pub fn set_pitch(&self, pitch: f32) -> i32 {}
#[java_method]
pub fn set_speech_rate(&self, speech_rate: f32) -> i32 {}
#[java_method]
#[deprecated(
note = "这不会在 TTS 引擎初始化时通知调用者。TextToSpeech(Context, TextToSpeech.OnInitListener, String) 可以与适当的引擎名称一起使用。此外,不能保证指定的引擎将被加载。如果未安装或禁用,则将应用用户/系统范围的默认值。"
)]
pub fn set_engine_by_package_name(&self, engine_package_name: String) -> i32 {}
#[java_method]
pub fn get_max_speech_input_length() -> i32 {}
#[java_method]
pub fn get_default_engine(&self) -> String {}
#[java_method]
pub fn get_current_engine(&self) -> String {}
#[java_method]
#[deprecated(note = "从 Ice creamwich 版本开始,用户设置永远不会强制覆盖应用程序的设置。")]
pub fn are_defaults_enforced(&self) -> bool {}
#[java_method]
pub fn speak<CS: CharSequence>(
&self,
text: &CS,
queue_mode: i32,
params: Option<Bundle>,
utterance_id: String,
) -> i32 {
}
}
#[allow(non_camel_case_types)]
#[java_interface(name = "android/speech/tts/TextToSpeech$OnInitListener")]
pub trait TextToSpeech_OnInitListener {
fn on_init(&self, status: i32);
}
#[doc(hidden)]
#[allow(non_camel_case_types)]
#[java_class(name = "android/speech/tts/TextToSpeech$OnInitListenerImpl")]
pub struct TextToSpeech_OnInitListenerImpl(Box<dyn Fn(i32) + Send + Sync>);
#[java_implement]
impl TextToSpeech_OnInitListener for TextToSpeech_OnInitListenerImpl {
fn on_init(&self, status: i32) {
self.0(status)
}
}
impl Default for TextToSpeech_OnInitListenerImplDefault {
fn default() -> Self {
Self(Box::new(|_| ()))
}
}
impl TextToSpeech_OnInitListenerImpl {
pub fn from_fn(func: impl Fn(/* status */ i32) + Send + Sync + 'static) -> Result<Arc<Self>> {
Self::new(TextToSpeech_OnInitListenerImplDefault(Box::new(func)))
}
}
#[cfg(feature = "test_android_speech_tts")]
pub fn test() {
use crate::{
android::app::Activity,
java::lang::{CharSequenceExt, CharSequenceImpl},
};
let context = Activity::fetch().unwrap();
let init_listener = TextToSpeech_OnInitListenerImpl::from_fn(|status| {
println!("Tts is initialized status: {}.", status)
})
.unwrap();
let tts = TextToSpeech::new(&context, init_listener.as_ref());
assert!(
tts.to_string()
.starts_with("android.speech.tts.TextToSpeech")
);
tts.stop();
assert_eq!(false, tts.is_speaking());
assert_eq!(TextToSpeech::SUCCESS, tts.set_pitch(0.8f32));
assert_eq!(TextToSpeech::SUCCESS, tts.set_speech_rate(0.8f32));
assert!(!tts.get_default_engine().is_empty());
assert!(!tts.get_current_engine().is_empty());
tts.speak(
&"你好".to_char_sequence::<CharSequenceImpl>().unwrap(),
TextToSpeech::QUEUE_ADD,
None,
"test".to_string(),
);
tts.shutdown();
assert!(TextToSpeech::get_max_speech_input_length() > 0);
}