This is a personal project to experiment a little bit with WASM, Rust and Svelte. The objective is to create a SPA that can use the WebSpeech API to recognize speech, then convert the user voice and try to pedict what they are filling with NLP.
Please take a look to linfa, Machine Learning framework for Rust!
- SvelteKit
- Rust
- TailwindCSS
The idea is simple, vectorize a large set of sentences that correspond to an emotion, then train a logistic regression model based on the vectorized sentences where the targets are the emotions. Unfortunately it has not been as easy as I thought to implement this, since my only experience in machine learning has been with SK-learn and I had never used Rust in my life.
I know emotion dont work like this, they're more like a spectrum, you can't fully detect the emotions of something just from what it says, there are many factors at play, such as volume of voice and body language. This project is more to learn more aboutNLP.
You have to make certain steps if you want to tun WASM in SvelteKit, unfortunlty I havent made it run using the hot reload fucntion Svelte, only building and previewing :c The steps you must follow to connect WASM are :
- Make a Cargo lib with
cargo new --lib cratename
- Add this to your Cargo.toml
[package]
name = "cratename"
version = "0.1.0"
edition = "2021"
[lib]
crate-type = ["cdylib", "rlib"]
[dependencies]
wasm-bindgen = "0.2.83"
wee_alloc = { version = "0.4.5", optional = true }
[dev-dependencies]
wasm-bindgen-test = "0.3.33"
[profile.release]
opt-level = "s"
- Compile using
wasm-pack
, with the fallowing flags :
wasm-pack build --target web --release
-
Rename the pkg folder to cratename and move it to /src
-
Add the following line in package.json
"cratename": "file:src/cratename"
- Run
npm i
- That's it! (If you have more questions send me a message)
This page its actually deployed using the Vercel hosting service (excelent DX, by the way), but the project is configured to build an SPA, not an SSR page, to test how the model work without having to relay a lot in the server.