mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
format services/ime-plugin-tts
This commit is contained in:
parent
fa06d187db
commit
411e0ca9d8
1 changed files with 18 additions and 20 deletions
|
|
@ -2,11 +2,10 @@
|
||||||
#![cfg_attr(target_os = "none", no_main)]
|
#![cfg_attr(target_os = "none", no_main)]
|
||||||
|
|
||||||
use ime_plugin_api::*;
|
use ime_plugin_api::*;
|
||||||
|
|
||||||
use xous_ipc::{String, Buffer};
|
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use tts_frontend::*;
|
use tts_frontend::*;
|
||||||
use xous::msg_scalar_unpack;
|
use xous::msg_scalar_unpack;
|
||||||
|
use xous_ipc::{Buffer, String};
|
||||||
|
|
||||||
fn main() -> ! {
|
fn main() -> ! {
|
||||||
log_server::init_wait().unwrap();
|
log_server::init_wait().unwrap();
|
||||||
|
|
@ -15,15 +14,12 @@ fn main() -> ! {
|
||||||
|
|
||||||
let xns = xous_names::XousNames::new().unwrap();
|
let xns = xous_names::XousNames::new().unwrap();
|
||||||
// one connection only, should be the GAM
|
// one connection only, should be the GAM
|
||||||
let ime_sh_sid = xns.register_name(ime_plugin_tts::SERVER_NAME_IME_PLUGIN_TTS, None).expect("can't register server");
|
let ime_sh_sid =
|
||||||
|
xns.register_name(ime_plugin_tts::SERVER_NAME_IME_PLUGIN_TTS, None).expect("can't register server");
|
||||||
log::trace!("registered with NS -- {:?}", ime_sh_sid);
|
log::trace!("registered with NS -- {:?}", ime_sh_sid);
|
||||||
let tts = TtsFrontend::new(&xns).unwrap();
|
let tts = TtsFrontend::new(&xns).unwrap();
|
||||||
|
|
||||||
let mytriggers = PredictionTriggers {
|
let mytriggers = PredictionTriggers { newline: true, punctuation: true, whitespace: true };
|
||||||
newline: true,
|
|
||||||
punctuation: true,
|
|
||||||
whitespace: true,
|
|
||||||
};
|
|
||||||
|
|
||||||
log::trace!("ready to accept requests");
|
log::trace!("ready to accept requests");
|
||||||
let mut api_token: Option<[u32; 4]> = None;
|
let mut api_token: Option<[u32; 4]> = None;
|
||||||
|
|
@ -31,9 +27,8 @@ fn main() -> ! {
|
||||||
let mut msg = xous::receive_message(ime_sh_sid).unwrap();
|
let mut msg = xous::receive_message(ime_sh_sid).unwrap();
|
||||||
match FromPrimitive::from_usize(msg.body.id()) {
|
match FromPrimitive::from_usize(msg.body.id()) {
|
||||||
Some(Opcode::Acquire) => {
|
Some(Opcode::Acquire) => {
|
||||||
let mut buffer = unsafe {
|
let mut buffer =
|
||||||
Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap())
|
unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||||
};
|
|
||||||
let mut ret = buffer.to_original::<AcquirePredictor, _>().unwrap();
|
let mut ret = buffer.to_original::<AcquirePredictor, _>().unwrap();
|
||||||
if api_token.is_none() {
|
if api_token.is_none() {
|
||||||
if let Some(token) = ret.token {
|
if let Some(token) = ret.token {
|
||||||
|
|
@ -61,31 +56,34 @@ fn main() -> ! {
|
||||||
log::warn!("Release called on a predictor that was in a released state");
|
log::warn!("Release called on a predictor that was in a released state");
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
Some(Opcode::Input) => {
|
Some(Opcode::Input) => {}
|
||||||
}
|
|
||||||
Some(Opcode::Picked) => {
|
Some(Opcode::Picked) => {
|
||||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||||
let s = buffer.as_flat::<String::<4000>, _>().unwrap();
|
let s = buffer.as_flat::<String<4000>, _>().unwrap();
|
||||||
tts.tts_simple(s.as_str()).unwrap();
|
tts.tts_simple(s.as_str()).unwrap();
|
||||||
}
|
}
|
||||||
Some(Opcode::Prediction) => {
|
Some(Opcode::Prediction) => {
|
||||||
// we don't check the API token, because we always return `false`
|
// we don't check the API token, because we always return `false`
|
||||||
let mut buffer = unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
let mut buffer =
|
||||||
|
unsafe { Buffer::from_memory_message_mut(msg.body.memory_message_mut().unwrap()) };
|
||||||
let mut prediction: Prediction = buffer.to_original::<Prediction, _>().unwrap();
|
let mut prediction: Prediction = buffer.to_original::<Prediction, _>().unwrap();
|
||||||
prediction.valid = false;
|
prediction.valid = false;
|
||||||
buffer.replace(Return::Prediction(prediction)).expect("couldn't return Prediction");
|
buffer.replace(Return::Prediction(prediction)).expect("couldn't return Prediction");
|
||||||
}
|
}
|
||||||
Some(Opcode::Unpick) => {
|
Some(Opcode::Unpick) => {}
|
||||||
}
|
|
||||||
Some(Opcode::GetPredictionTriggers) => {
|
Some(Opcode::GetPredictionTriggers) => {
|
||||||
xous::return_scalar(msg.sender, mytriggers.into()).expect("couldn't return GetPredictionTriggers");
|
xous::return_scalar(msg.sender, mytriggers.into())
|
||||||
|
.expect("couldn't return GetPredictionTriggers");
|
||||||
}
|
}
|
||||||
Some(Opcode::Quit) => {
|
Some(Opcode::Quit) => {
|
||||||
if api_token.is_some() {
|
if api_token.is_some() {
|
||||||
log::error!("received quit, goodbye!"); break;
|
log::error!("received quit, goodbye!");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {log::error!("unknown Opcode");}
|
None => {
|
||||||
|
log::error!("unknown Opcode");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log::trace!("main loop exit, destroying servers");
|
log::trace!("main loop exit, destroying servers");
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue