mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-17 08:40:52 +00:00
add speech rate library call and default setting
350 wpm was the requested default!
This commit is contained in:
parent
1227ee06ab
commit
446317bdd4
8 changed files with 63 additions and 20 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
|
@ -947,6 +947,7 @@ dependencies = [
|
||||||
"susres",
|
"susres",
|
||||||
"ticktimer-server",
|
"ticktimer-server",
|
||||||
"trng",
|
"trng",
|
||||||
|
"tts-frontend",
|
||||||
"utralib",
|
"utralib",
|
||||||
"xous",
|
"xous",
|
||||||
"xous-ipc 0.9.7",
|
"xous-ipc 0.9.7",
|
||||||
|
|
@ -3099,9 +3100,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "xous-tts-backend"
|
name = "xous-tts-backend"
|
||||||
version = "0.1.2"
|
version = "0.1.3"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b895859a53d60cf076ce5af2b0520390a5fada412fa5dd6e9b92e4c1b4020ce7"
|
checksum = "a2d0fd1ceeb73a0eb226efc0f772dd643c25bc59b04db4bb593b4273d7253624"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"log",
|
"log",
|
||||||
"num-derive",
|
"num-derive",
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,13 @@ susres = {path = "../susres"} # used for the sleep now menu item
|
||||||
enum_dispatch = "0.3.7" # used for trait-based dispatch off of multiple layout objects.
|
enum_dispatch = "0.3.7" # used for trait-based dispatch off of multiple layout objects.
|
||||||
locales = {path = "../../locales"}
|
locales = {path = "../../locales"}
|
||||||
|
|
||||||
|
tts-frontend = {path="../tts"}
|
||||||
|
|
||||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||||
utralib = {path = "../../utralib"}
|
utralib = {path = "../../utralib"}
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
debugprint = []
|
debugprint = []
|
||||||
|
tts = []
|
||||||
# default = ["debugprint"] # "debugprint"
|
# default = ["debugprint"] # "debugprint"
|
||||||
default = []
|
default = []
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,8 @@ use num_traits::*;
|
||||||
|
|
||||||
use graphics_server::api::{PixelColor, TextBounds, DrawStyle, GlyphStyle};
|
use graphics_server::api::{PixelColor, TextBounds, DrawStyle, GlyphStyle};
|
||||||
|
|
||||||
|
#[cfg(feature = "tts")]
|
||||||
|
use tts_frontend::*;
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Menu<'a> {
|
pub struct Menu<'a> {
|
||||||
pub sid: xous::SID,
|
pub sid: xous::SID,
|
||||||
|
|
@ -26,6 +28,8 @@ pub struct Menu<'a> {
|
||||||
pub canvas_width: Option<i16>,
|
pub canvas_width: Option<i16>,
|
||||||
pub helper_data: Option<Buffer<'a>>,
|
pub helper_data: Option<Buffer<'a>>,
|
||||||
pub name: std::string::String,
|
pub name: std::string::String,
|
||||||
|
#[cfg(feature = "tts")]
|
||||||
|
pub tts: TtsFrontend,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
#[derive(Debug, num_derive::FromPrimitive, num_derive::ToPrimitive)]
|
||||||
|
|
@ -57,6 +61,8 @@ impl<'a> Menu<'a> {
|
||||||
log::debug!("requesting content canvas for menu");
|
log::debug!("requesting content canvas for menu");
|
||||||
let canvas = gam.request_content_canvas(authtoken.unwrap()).expect("couldn't get my content canvas from GAM");
|
let canvas = gam.request_content_canvas(authtoken.unwrap()).expect("couldn't get my content canvas from GAM");
|
||||||
let line_height = gam.glyph_height_hint(GlyphStyle::Cjk).expect("couldn't get glyph height hint") as i16 + 2;
|
let line_height = gam.glyph_height_hint(GlyphStyle::Cjk).expect("couldn't get glyph height hint") as i16 + 2;
|
||||||
|
#[cfg(feature="tts")]
|
||||||
|
let tts = TtsFrontend::new(&xns).unwrap();
|
||||||
Menu {
|
Menu {
|
||||||
sid,
|
sid,
|
||||||
gam,
|
gam,
|
||||||
|
|
@ -71,6 +77,8 @@ impl<'a> Menu<'a> {
|
||||||
canvas_width: None,
|
canvas_width: None,
|
||||||
helper_data: None,
|
helper_data: None,
|
||||||
name: std::string::String::from(name),
|
name: std::string::String::from(name),
|
||||||
|
#[cfg(feature="tts")]
|
||||||
|
tts,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn activate(&self) {
|
pub fn activate(&self) {
|
||||||
|
|
@ -164,6 +172,8 @@ impl<'a> Menu<'a> {
|
||||||
|
|
||||||
if with_marker {
|
if with_marker {
|
||||||
write!(item_tv.text, "\u{25B6}").unwrap();
|
write!(item_tv.text, "\u{25B6}").unwrap();
|
||||||
|
#[cfg(feature="tts")]
|
||||||
|
self.tts.tts_simple(item.name.as_str().unwrap()).unwrap();
|
||||||
} else {
|
} else {
|
||||||
write!(item_tv.text, "\t").unwrap();
|
write!(item_tv.text, "\t").unwrap();
|
||||||
}
|
}
|
||||||
|
|
@ -269,6 +279,10 @@ impl<'a> Menu<'a> {
|
||||||
}
|
}
|
||||||
log::trace!("menu redraw##");
|
log::trace!("menu redraw##");
|
||||||
self.gam.redraw().unwrap();
|
self.gam.redraw().unwrap();
|
||||||
|
#[cfg(feature="tts")]
|
||||||
|
{
|
||||||
|
// self.tts.tts_simple(&self.name).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
fn num_items(&self) -> usize {
|
fn num_items(&self) -> usize {
|
||||||
self.items.len()
|
self.items.len()
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ num-derive = {version = "0.3.3", default-features = false}
|
||||||
num-traits = {version = "0.2.14", default-features = false}
|
num-traits = {version = "0.2.14", default-features = false}
|
||||||
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
|
rkyv = {version = "0.4.3", default-features = false, features = ["const_generics"]}
|
||||||
# xous-tts-backend = {path="../../../tts-backend"}
|
# xous-tts-backend = {path="../../../tts-backend"}
|
||||||
xous-tts-backend = "0.1.2"
|
xous-tts-backend = "0.1.3"
|
||||||
codec = {path = "../codec"}
|
codec = {path = "../codec"}
|
||||||
|
|
||||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@ pub(crate) enum Opcode {
|
||||||
CodecCb,
|
CodecCb,
|
||||||
/// Stops audio playback immediately. Does not stop wave generation.
|
/// Stops audio playback immediately. Does not stop wave generation.
|
||||||
CodecStop,
|
CodecStop,
|
||||||
|
/// Set words per minute
|
||||||
|
SetWordsPerMinute,
|
||||||
/// Exits the server
|
/// Exits the server
|
||||||
Quit,
|
Quit,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
pub mod api;
|
pub mod api;
|
||||||
pub use api::*;
|
pub use api::*;
|
||||||
use xous::CID;
|
use xous::{CID, send_message, Message};
|
||||||
use xous_ipc::Buffer;
|
use xous_ipc::Buffer;
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
|
|
||||||
|
|
@ -27,6 +27,11 @@ impl TtsFrontend {
|
||||||
let buf = Buffer::into_buf(msg).or(Err(xous::Error::InternalError))?;
|
let buf = Buffer::into_buf(msg).or(Err(xous::Error::InternalError))?;
|
||||||
buf.lend(self.conn, Opcode::TextToSpeech.to_u32().unwrap()).map(|_| ())
|
buf.lend(self.conn, Opcode::TextToSpeech.to_u32().unwrap()).map(|_| ())
|
||||||
}
|
}
|
||||||
|
pub fn set_words_per_minute(&self, wpm: u32) -> Result<(), xous::Error> {
|
||||||
|
send_message(self.conn,
|
||||||
|
Message::new_scalar(Opcode::SetWordsPerMinute.to_usize().unwrap(), wpm as usize, 0, 0, 0)
|
||||||
|
).map(|_| ())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
use core::sync::atomic::{AtomicU32, Ordering};
|
use core::sync::atomic::{AtomicU32, Ordering};
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ use std::sync::{Arc, Mutex};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
|
||||||
|
const DEFAULT_WPM: u32 = 350;
|
||||||
|
|
||||||
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
#[derive(num_derive::FromPrimitive, num_derive::ToPrimitive, Debug)]
|
||||||
pub(crate) enum WaveOp {
|
pub(crate) enum WaveOp {
|
||||||
Return,
|
Return,
|
||||||
|
|
@ -90,7 +92,13 @@ fn xmain() -> ! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
tts_be.tts_config(wav_sid.to_array(), WaveOp::Return.to_u32().unwrap(), None).unwrap();
|
let mut wpm = DEFAULT_WPM;
|
||||||
|
tts_be.tts_config(
|
||||||
|
wav_sid.to_array(),
|
||||||
|
WaveOp::Return.to_u32().unwrap(),
|
||||||
|
None,
|
||||||
|
Some(wpm)
|
||||||
|
).unwrap();
|
||||||
let mut just_initiated = false;
|
let mut just_initiated = false;
|
||||||
loop {
|
loop {
|
||||||
let msg = xous::receive_message(tts_sid).unwrap();
|
let msg = xous::receive_message(tts_sid).unwrap();
|
||||||
|
|
@ -158,6 +166,10 @@ fn xmain() -> ! {
|
||||||
log::info!("stop called. Immediate stop and loss of audio data.");
|
log::info!("stop called. Immediate stop and loss of audio data.");
|
||||||
codec.abort().unwrap();
|
codec.abort().unwrap();
|
||||||
}
|
}
|
||||||
|
Some(Opcode::SetWordsPerMinute) => msg_scalar_unpack!(msg, wpm_arg, _, _, _, {
|
||||||
|
wpm = wpm_arg as u32;
|
||||||
|
tts_be.tts_config(wav_sid.to_array(), WaveOp::Return.to_u32().unwrap(), None, Some(wpm)).unwrap();
|
||||||
|
}),
|
||||||
Some(Opcode::Quit) => {
|
Some(Opcode::Quit) => {
|
||||||
send_message(wav_cid,
|
send_message(wav_cid,
|
||||||
Message::new_blocking_scalar(WaveOp::Quit.to_usize().unwrap(), 0, 0, 0, 0)
|
Message::new_blocking_scalar(WaveOp::Quit.to_usize().unwrap(), 0, 0, 0, 0)
|
||||||
|
|
|
||||||
|
|
@ -199,21 +199,27 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
renode_image(false, &cbtest_pkgs, &[], None, None)?
|
renode_image(false, &cbtest_pkgs, &[], None, None)?
|
||||||
},
|
},
|
||||||
Some("tts") => {
|
Some("tts") => {
|
||||||
println!("Fetching tts executable from build server...");
|
let tts_exec_string = if false {
|
||||||
let tmp_dir = tempfile::Builder::new().prefix("bins").tempdir()?;
|
println!("Fetching tts executable from build server...");
|
||||||
let tts_exec_name = tmp_dir.path().join("espeak-embedded");
|
let tmp_dir = tempfile::Builder::new().prefix("bins").tempdir()?;
|
||||||
let tts_exec_string = tts_exec_name.clone().into_os_string().into_string().unwrap();
|
let tts_exec_name = tmp_dir.path().join("espeak-embedded");
|
||||||
let mut tts_exec_file = OpenOptions::new()
|
let tts_exec_string = tts_exec_name.clone().into_os_string().into_string().unwrap();
|
||||||
.read(true)
|
let mut tts_exec_file = OpenOptions::new()
|
||||||
.write(true)
|
.read(true)
|
||||||
.create(true)
|
.write(true)
|
||||||
.truncate(true)
|
.create(true)
|
||||||
.open(tts_exec_name).expect("Can't open our version file for writing");
|
.truncate(true)
|
||||||
let mut freader = ureq::get("https://ci.betrusted.io/job/espeak-embedded/lastSuccessfulBuild/artifact/target/riscv32imac-unknown-xous-elf/release/espeak-embedded")
|
.open(tts_exec_name).expect("Can't open our version file for writing");
|
||||||
.call()?
|
let mut freader = ureq::get("https://ci.betrusted.io/job/espeak-embedded/lastSuccessfulBuild/artifact/target/riscv32imac-unknown-xous-elf/release/espeak-embedded")
|
||||||
.into_reader();
|
.call()?
|
||||||
std::io::copy(&mut freader, &mut tts_exec_file)?;
|
.into_reader();
|
||||||
println!("TTS exec is {} bytes", tts_exec_file.metadata().unwrap().len());
|
std::io::copy(&mut freader, &mut tts_exec_file)?;
|
||||||
|
println!("TTS exec is {} bytes", tts_exec_file.metadata().unwrap().len());
|
||||||
|
tts_exec_string
|
||||||
|
} else {
|
||||||
|
println!("****** WARNING: using local dev image. Do not check this configuration in! ******");
|
||||||
|
"../espeak-embedded/target/riscv32imac-unknown-xous-elf/release/espeak-embedded".to_string()
|
||||||
|
};
|
||||||
|
|
||||||
let mut args = env::args();
|
let mut args = env::args();
|
||||||
args.nth(1);
|
args.nth(1);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue