add tts locale to hello example

This commit is contained in:
bunnie 2022-03-21 00:22:54 +08:00
parent 731b847560
commit b4d20a643c
4 changed files with 26 additions and 1 deletions

2
Cargo.lock generated
View file

@ -1035,10 +1035,12 @@ version = "0.1.0"
dependencies = [
"gam",
"graphics-server",
"locales",
"log",
"log-server",
"num-derive",
"num-traits",
"tts-frontend",
"xous",
"xous-ipc 0.9.7",
"xous-names",

View file

@ -13,3 +13,9 @@ log-server = { path = "../../services/log-server" }
xous-names = { path = "../../services/xous-names" }
gam = {path = "../../services/gam" }
graphics-server = {path = "../../services/graphics-server" }
locales = {path = "../../locales"}
tts-frontend = {path="../../services/tts"}
[features]
tts = []
default = []

View file

@ -0,0 +1,8 @@
{
"helloworld.hello": {
"en": "Hello World!",
"ja": "Hello World!",
"zh": "大家好!",
"en-tts": "Hello World!"
}
}

View file

@ -5,6 +5,9 @@ use core::fmt::Write;
use graphics_server::api::GlyphStyle;
use graphics_server::{DrawStyle, Gid, PixelColor, Point, Rectangle, TextBounds, TextView};
use num_traits::*;
use locales::t;
#[cfg(feature = "tts")]
use tts_frontend::*;
/// Basic 'Hello World!' application that draws a simple
/// TextView to the screen.
@ -26,6 +29,8 @@ struct Hello {
gam: gam::Gam,
_gam_token: [u32; 4],
screensize: Point,
#[cfg(feature = "tts")]
tts: TtsFrontend,
}
impl Hello {
@ -57,6 +62,8 @@ impl Hello {
_gam_token: gam_token,
content,
screensize,
#[cfg(feature = "tts")]
tts: TtsFrontend::new(xns).unwrap(),
}
}
@ -98,7 +105,9 @@ impl Hello {
text_view.clear_area = true;
text_view.rounded_border = Some(3);
text_view.style = GlyphStyle::Regular;
write!(text_view.text, "{}", "Hello world!").expect("Could not write to text view");
write!(text_view.text, "{}", t!("helloworld.hello", xous::LANG)).expect("Could not write to text view");
#[cfg(feature="tts")]
self.tts.tts_simple(t!("helloworld.hello", xous::LANG)).unwrap();
self.gam
.post_textview(&mut text_view)