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:
bunnie 2022-03-11 19:08:39 +08:00
parent 34c9d83cba
commit bbccf1c2a7
4 changed files with 35 additions and 11 deletions

View file

@ -28,7 +28,7 @@ impl From<usize> for KeyMap {
1 => KeyMap::Azerty, 1 => KeyMap::Azerty,
2 => KeyMap::Qwertz, 2 => KeyMap::Qwertz,
3 => KeyMap::Dvorak, 3 => KeyMap::Dvorak,
254 => KeyMap::Braille, // braille has only one mapping available 4 => KeyMap::Braille,
_ => KeyMap::Qwerty, _ => KeyMap::Qwerty,
} }
} }
@ -41,7 +41,7 @@ impl Into<usize> for KeyMap {
KeyMap::Azerty => 1, KeyMap::Azerty => 1,
KeyMap::Qwertz => 2, KeyMap::Qwertz => 2,
KeyMap::Dvorak => 3, KeyMap::Dvorak => 3,
KeyMap::Braille => 254, KeyMap::Braille => 4,
KeyMap::Undefined => 255, KeyMap::Undefined => 255,
} }
} }

View file

@ -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]), action_payload: MenuPayload::Scalar([code as u32, 0, 0, 0]),
close_on_select: true, 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") menu_matic(menu_items, gam::KBD_MENU_NAME, Some(kbd_mgr)).expect("couldn't create MenuMatic manager")
} }

View file

@ -13,7 +13,8 @@ pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, status_conn: xous::CID, com:
let mut menuitems = Vec::<MenuItem>::new(); 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 { menuitems.push(MenuItem {
name: String::from_str(t!("mainmenu.backlighton", xous::LANG)), name: String::from_str(t!("mainmenu.backlighton", xous::LANG)),
action_conn: Some(com.conn()), 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, close_on_select: true,
}); });
#[cfg(not(feature="tts"))] //#[cfg(not(feature="tts"))]
menuitems.push(MenuItem { menuitems.push(MenuItem {
name: String::from_str(t!("mainmenu.backlightoff", xous::LANG)), name: String::from_str(t!("mainmenu.backlightoff", xous::LANG)),
action_conn: Some(com.conn()), 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, close_on_select: true,
}); });
#[cfg(not(feature="tts"))]
menuitems.push(MenuItem { menuitems.push(MenuItem {
name: String::from_str(t!("mainmenu.kbd", xous::LANG)), name: String::from_str(t!("mainmenu.kbd", xous::LANG)),
action_conn: Some(status_conn), 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]), action_payload: MenuPayload::Scalar([0, 0, 0, 0]),
close_on_select: true, close_on_select: true,
}); });
menuitems.push(MenuItem { menuitems.push(MenuItem {
name: String::from_str(t!("mainmenu.closemenu", xous::LANG)), name: String::from_str(t!("mainmenu.closemenu", xous::LANG)),
action_conn: None, action_conn: None,

View file

@ -15,6 +15,8 @@ use std::collections::VecDeque;
const DEFAULT_WPM: u32 = 350; const DEFAULT_WPM: u32 = 350;
const WAIT_INTERVAL: usize = 50; // milliseconds to wait before polling if a phrase is finished. 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)] #[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
pub(crate) enum WaveOp { pub(crate) enum WaveOp {
@ -52,10 +54,22 @@ fn xmain() -> ! {
// let tts_cid = tts_cid.clone(); // let tts_cid = tts_cid.clone();
let synth_done = synth_done.clone(); let synth_done = synth_done.clone();
move || { move || {
let tt = ticktimer_server::Ticktimer::new().unwrap();
loop { loop {
let msg = xous::receive_message(wav_sid).unwrap(); let msg = xous::receive_message(wav_sid).unwrap();
match FromPrimitive::from_usize(msg.body.id()) { match FromPrimitive::from_usize(msg.body.id()) {
Some(WaveOp::Return) => { 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 buffer = unsafe { Buffer::from_memory_message(msg.body.memory_message().unwrap()) };
let wavdat = buffer.to_original::<TtsBackendData, _>().unwrap(); let wavdat = buffer.to_original::<TtsBackendData, _>().unwrap();
let mut buf = wavbuf.lock().unwrap(); let mut buf = wavbuf.lock().unwrap();
@ -113,7 +127,7 @@ fn xmain() -> ! {
free_play free_play
}; };
frame_count += frames_to_push as u32; 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(); let mut locked_buf = wavbuf.lock().unwrap();
if just_initiated.load(Ordering::SeqCst) { 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 // 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) => { Some(Opcode::TextToSpeech) => {
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 msg = buffer.to_original::<TtsFrontendMsg, _>().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 wavbuf.lock().unwrap().clear(); // this will truncate any buffered audio that is playing
synth_done.store(false, Ordering::SeqCst); synth_done.store(false, Ordering::SeqCst);
tts_be.tts_simple(msg.text.as_str().unwrap()).unwrap(); tts_be.tts_simple(msg.text.as_str().unwrap()).unwrap();
just_initiated.store(true, Ordering::SeqCst); just_initiated.store(true, Ordering::SeqCst);
log::debug!("resuming codec"); log::trace!("resuming codec");
codec.resume().unwrap(); codec.resume().unwrap();
}, },
Some(Opcode::TextToSpeechBlocking) => { Some(Opcode::TextToSpeechBlocking) => {
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 msg = buffer.to_original::<TtsFrontendMsg, _>().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 wavbuf.lock().unwrap().clear(); // this will truncate any buffered audio that is playing
synth_done.store(false, Ordering::SeqCst); synth_done.store(false, Ordering::SeqCst);
tts_be.tts_simple(msg.text.as_str().unwrap()).unwrap(); tts_be.tts_simple(msg.text.as_str().unwrap()).unwrap();
just_initiated.store(true, Ordering::SeqCst); just_initiated.store(true, Ordering::SeqCst);
log::debug!("resuming codec (blocking)"); log::trace!("resuming codec (blocking)");
codec.resume().unwrap(); codec.resume().unwrap();
while !synth_done.load(Ordering::SeqCst) { while !synth_done.load(Ordering::SeqCst) {
// this is done fairly "fast" because the synth buf fills quickly // this is done fairly "fast" because the synth buf fills quickly