diff --git a/Makefile.toml b/Makefile.toml index 6697f15..d5cda6b 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -12,4 +12,16 @@ script = [ [tasks.log-android] command = "adb" -args = ["logcat", "RustStdoutStderr:D", "*:S"] \ No newline at end of file +args = ["logcat", "RustStdoutStderr:D", "*:S"] + +[tasks.install-trunk] +install_crate = { crate_name = "trunk", binary = "trunk", test_arg = "--help" } + +[tasks.install-wasm-bindgen-cli] +install_crate = { crate_name = "wasm-bindgen-cli", binary = "wasm-bindgen", test_arg = "--help" } + +[tasks.run-web-example] +dependencies = ["install-trunk", "install-wasm-bindgen-cli"] +cwd = "examples/web" +command = "trunk" +args = ["serve"] \ No newline at end of file diff --git a/examples/web/.cargo/config b/examples/web/.cargo/config new file mode 100644 index 0000000..435ed75 --- /dev/null +++ b/examples/web/.cargo/config @@ -0,0 +1,2 @@ +[build] +target = "wasm32-unknown-unknown" \ No newline at end of file diff --git a/examples/web/.gitignore b/examples/web/.gitignore new file mode 100644 index 0000000..53c37a1 --- /dev/null +++ b/examples/web/.gitignore @@ -0,0 +1 @@ +dist \ No newline at end of file diff --git a/examples/web/Cargo.toml b/examples/web/Cargo.toml new file mode 100644 index 0000000..e93d316 --- /dev/null +++ b/examples/web/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "web" +version = "0.1.0" +authors = ["Nolan Darilek "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +seed = "0.8" +tts = { path = "../.." } \ No newline at end of file diff --git a/examples/web/index.html b/examples/web/index.html new file mode 100644 index 0000000..15e486f --- /dev/null +++ b/examples/web/index.html @@ -0,0 +1,12 @@ + + + + + Example + + + +
+ + + \ No newline at end of file diff --git a/examples/web/src/main.rs b/examples/web/src/main.rs new file mode 100644 index 0000000..5f35742 --- /dev/null +++ b/examples/web/src/main.rs @@ -0,0 +1,111 @@ +#![allow(clippy::wildcard_imports)] +use seed::{prelude::*, *}; + +use tts::TTS; + +#[derive(Clone)] +struct Model { + text: String, + tts: TTS, +} + +#[derive(Clone)] +enum Msg { + TextChanged(String), + RateChanged(String), + PitchChanged(String), + VolumeChanged(String), + Speak, +} + +fn init(_: Url, _: &mut impl Orders) -> Model { + let tts = TTS::default().unwrap(); + Model { + text: Default::default(), + tts, + } +} + +fn update(msg: Msg, model: &mut Model, _: &mut impl Orders) { + use Msg::*; + match msg { + TextChanged(text) => model.text = text, + RateChanged(rate) => { + let rate = rate.parse::().unwrap(); + model.tts.set_rate(rate).unwrap(); + } + PitchChanged(pitch) => { + let pitch = pitch.parse::().unwrap(); + model.tts.set_pitch(pitch).unwrap(); + } + VolumeChanged(volume) => { + let volume = volume.parse::().unwrap(); + model.tts.set_volume(volume).unwrap(); + } + Speak => { + model.tts.speak(&model.text, false).unwrap(); + } + } +} + +fn view(model: &Model) -> Node { + form![ + div![label![ + "Text to speak", + input![ + attrs! { + At::Value => model.text, + At::AutoFocus => AtValue::None, + }, + input_ev(Ev::Input, Msg::TextChanged) + ], + ],], + div![label![ + "Rate", + input![ + attrs! { + At::Type => "number", + At::Value => model.tts.get_rate().unwrap(), + At::Min => model.tts.min_rate(), + At::Max => model.tts.max_rate() + }, + input_ev(Ev::Input, Msg::RateChanged) + ], + ],], + div![label![ + "Pitch", + input![ + attrs! { + At::Type => "number", + At::Value => model.tts.get_pitch().unwrap(), + At::Min => model.tts.min_pitch(), + At::Max => model.tts.max_pitch() + }, + input_ev(Ev::Input, Msg::PitchChanged) + ], + ],], + div![label![ + "Volume", + input![ + attrs! { + At::Type => "number", + At::Value => model.tts.get_volume().unwrap(), + At::Min => model.tts.min_volume(), + At::Max => model.tts.max_volume() + }, + input_ev(Ev::Input, Msg::VolumeChanged) + ], + ],], + button![ + "Speak", + ev(Ev::Click, |e| { + e.prevent_default(); + Msg::Speak + }), + ], + ] +} + +fn main() { + App::start("app", init, update, view); +}