mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +00:00
reached a reasonable integration point for tts until braille protos are in
tts is working fairly well and much more stably, menus and ui elements are wired up for tts. just waiting for the latest braille keyboard pcb to come in and then we'll be able to fire off some prototypes...
This commit is contained in:
parent
34c9d83cba
commit
bbccf1c2a7
4 changed files with 35 additions and 11 deletions
|
|
@ -28,7 +28,7 @@ impl From<usize> for KeyMap {
|
|||
1 => KeyMap::Azerty,
|
||||
2 => KeyMap::Qwertz,
|
||||
3 => KeyMap::Dvorak,
|
||||
254 => KeyMap::Braille, // braille has only one mapping available
|
||||
4 => KeyMap::Braille,
|
||||
_ => KeyMap::Qwerty,
|
||||
}
|
||||
}
|
||||
|
|
@ -41,7 +41,7 @@ impl Into<usize> for KeyMap {
|
|||
KeyMap::Azerty => 1,
|
||||
KeyMap::Qwertz => 2,
|
||||
KeyMap::Dvorak => 3,
|
||||
KeyMap::Braille => 254,
|
||||
KeyMap::Braille => 4,
|
||||
KeyMap::Undefined => 255,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,6 +44,17 @@ pub fn create_kbd_menu(status_conn: xous::CID, kbd_mgr: xous::SID) -> MenuMatic
|
|||
action_payload: MenuPayload::Scalar([code as u32, 0, 0, 0]),
|
||||
close_on_select: true,
|
||||
});
|
||||
#[cfg(feature="tts")]
|
||||
{
|
||||
let code: usize = KeyMap::Braille.into();
|
||||
menu_items.push(MenuItem {
|
||||
name: xous_ipc::String::from_str("Braille"),
|
||||
action_conn: Some(status_conn),
|
||||
action_opcode: StatusOpcode::SetKeyboard.to_u32().unwrap(),
|
||||
action_payload: MenuPayload::Scalar([code as u32, 0, 0, 0]),
|
||||
close_on_select: true,
|
||||
});
|
||||
}
|
||||
|
||||
menu_matic(menu_items, gam::KBD_MENU_NAME, Some(kbd_mgr)).expect("couldn't create MenuMatic manager")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, status_conn: xous::CID, com:
|
|||
|
||||
let mut menuitems = Vec::<MenuItem>::new();
|
||||
|
||||
#[cfg(not(feature="tts"))] // no backlight on versions with no display
|
||||
// no backlight on versions with no display
|
||||
//#[cfg(not(feature="tts"))]
|
||||
menuitems.push(MenuItem {
|
||||
name: String::from_str(t!("mainmenu.backlighton", xous::LANG)),
|
||||
action_conn: Some(com.conn()),
|
||||
|
|
@ -22,7 +23,7 @@ pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, status_conn: xous::CID, com:
|
|||
close_on_select: true,
|
||||
});
|
||||
|
||||
#[cfg(not(feature="tts"))]
|
||||
//#[cfg(not(feature="tts"))]
|
||||
menuitems.push(MenuItem {
|
||||
name: String::from_str(t!("mainmenu.backlightoff", xous::LANG)),
|
||||
action_conn: Some(com.conn()),
|
||||
|
|
@ -98,7 +99,6 @@ pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, status_conn: xous::CID, com:
|
|||
close_on_select: true,
|
||||
});
|
||||
|
||||
#[cfg(not(feature="tts"))]
|
||||
menuitems.push(MenuItem {
|
||||
name: String::from_str(t!("mainmenu.kbd", xous::LANG)),
|
||||
action_conn: Some(status_conn),
|
||||
|
|
@ -106,7 +106,6 @@ pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, status_conn: xous::CID, com:
|
|||
action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
|
||||
close_on_select: true,
|
||||
});
|
||||
|
||||
menuitems.push(MenuItem {
|
||||
name: String::from_str(t!("mainmenu.closemenu", xous::LANG)),
|
||||
action_conn: None,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ use std::collections::VecDeque;
|
|||
|
||||
const DEFAULT_WPM: u32 = 350;
|
||||
const WAIT_INTERVAL: usize = 50; // milliseconds to wait before polling if a phrase is finished.
|
||||
const MAX_BUF_DEPTH: usize = (8000 * core::mem::size_of::<u16>()) * 3; // 8000 samples/s * num seconds to buffer
|
||||
const DRAIN_INTERVAL: usize = 100; // milliseconds to wait before checking if buffer has drained
|
||||
|
||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||
pub(crate) enum WaveOp {
|
||||
|
|
@ -52,10 +54,22 @@ fn xmain() -> ! {
|
|||
// let tts_cid = tts_cid.clone();
|
||||
let synth_done = synth_done.clone();
|
||||
move || {
|
||||
let tt = ticktimer_server::Ticktimer::new().unwrap();
|
||||
loop {
|
||||
let msg = xous::receive_message(wav_sid).unwrap();
|
||||
match FromPrimitive::from_usize(msg.body.id()) {
|
||||
Some(WaveOp::Return) => {
|
||||
// check to see if we need to apply backpressure on the synthesizer. If so, this is where we pause
|
||||
let mut capacity = { // put this in a block of its own to ensure the lock goes out of scope after we have measured the length
|
||||
wavbuf.lock().unwrap().len()
|
||||
};
|
||||
while capacity > MAX_BUF_DEPTH {
|
||||
// this effectively stalls the tts engine because the buffer sent to us is a `lend`, which is blocking.
|
||||
// by blocking this thread from copying the memory, we also block the synthesizer from generating more samples.
|
||||
log::info!("synth backpressure");
|
||||
tt.sleep_ms(DRAIN_INTERVAL).unwrap();
|
||||
capacity = wavbuf.lock().unwrap().len();
|
||||
}
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let wavdat = buffer.to_original::<TtsBackendData, _>().unwrap();
|
||||
let mut buf = wavbuf.lock().unwrap();
|
||||
|
|
@ -113,7 +127,7 @@ fn xmain() -> ! {
|
|||
free_play
|
||||
};
|
||||
frame_count += frames_to_push as u32;
|
||||
log::debug!("f{} p{}", frame_count, frames_to_push);
|
||||
log::trace!("f{} p{}", frame_count, frames_to_push);
|
||||
let mut locked_buf = wavbuf.lock().unwrap();
|
||||
if just_initiated.load(Ordering::SeqCst) {
|
||||
// prevent stutter if the synth buffer isn't ready yet and we got an early fill request from the codec
|
||||
|
|
@ -181,23 +195,23 @@ fn xmain() -> ! {
|
|||
Some(Opcode::TextToSpeech) => {
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let msg = buffer.to_original::<TtsFrontendMsg, _>().unwrap();
|
||||
log::info!("tts front end got string {}", msg.text.as_str().unwrap());
|
||||
log::debug!("tts front end got string {}", msg.text.as_str().unwrap());
|
||||
wavbuf.lock().unwrap().clear(); // this will truncate any buffered audio that is playing
|
||||
synth_done.store(false, Ordering::SeqCst);
|
||||
tts_be.tts_simple(msg.text.as_str().unwrap()).unwrap();
|
||||
just_initiated.store(true, Ordering::SeqCst);
|
||||
log::debug!("resuming codec");
|
||||
log::trace!("resuming codec");
|
||||
codec.resume().unwrap();
|
||||
},
|
||||
Some(Opcode::TextToSpeechBlocking) => {
|
||||
let buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
|
||||
let msg = buffer.to_original::<TtsFrontendMsg, _>().unwrap();
|
||||
log::info!("tts blocking front end got string {}", msg.text.as_str().unwrap());
|
||||
log::debug!("tts blocking front end got string {}", msg.text.as_str().unwrap());
|
||||
wavbuf.lock().unwrap().clear(); // this will truncate any buffered audio that is playing
|
||||
synth_done.store(false, Ordering::SeqCst);
|
||||
tts_be.tts_simple(msg.text.as_str().unwrap()).unwrap();
|
||||
just_initiated.store(true, Ordering::SeqCst);
|
||||
log::debug!("resuming codec (blocking)");
|
||||
log::trace!("resuming codec (blocking)");
|
||||
codec.resume().unwrap();
|
||||
while !synth_done.load(Ordering::SeqCst) {
|
||||
// this is done fairly "fast" because the synth buf fills quickly
|
||||
|
|
|
|||
Loading…
Reference in a new issue