frontend fixes & db rewrite with serde
This commit is contained in:
parent
a425d8f834
commit
78eb0c0080
37 changed files with 910 additions and 663 deletions
|
|
@ -19,9 +19,14 @@ platform-dirs.workspace = true
|
|||
rodio.workspace = true
|
||||
kira.workspace = true
|
||||
pv_recorder.workspace = true
|
||||
vosk.workspace = true
|
||||
rustpotter.workspace = true
|
||||
parking_lot.workspace = true
|
||||
|
||||
|
||||
# pv_recorder = { workspace = true, optional = true }
|
||||
vosk = { version = "0.3.1", optional = true }
|
||||
# rustpotter = { workspace = true, optional = true }
|
||||
|
||||
[features]
|
||||
default = ["jarvis_app"]
|
||||
jarvis_app = []
|
||||
jarvis_app = ["vosk"]
|
||||
|
|
@ -68,8 +68,12 @@ pub fn play_sound(filename: &PathBuf) {
|
|||
}
|
||||
|
||||
pub fn get_sound_directory() -> Option<PathBuf> {
|
||||
let voice = DB.get().unwrap().voice.as_str();
|
||||
let voice_path = SOUND_DIR.join(voice);
|
||||
let db = DB.get()?;
|
||||
|
||||
let voice_path = {
|
||||
let s = db.read();
|
||||
SOUND_DIR.join(&s.voice)
|
||||
};
|
||||
|
||||
match voice_path.exists() && voice_path.cmp(&SOUND_DIR) != Ordering::Equal {
|
||||
true => Some(voice_path),
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ impl fmt::Display for WakeWordEngine {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub enum SpeechToTextEngine {
|
||||
Vosk,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,10 +49,10 @@ pub fn save_settings(settings: &structs::Settings) -> Result<(), std::io::Error>
|
|||
let db_file_path = get_db_file_path();
|
||||
|
||||
std::fs::write(
|
||||
db_file_path,
|
||||
&db_file_path,
|
||||
serde_json::to_string_pretty(&settings).unwrap(),
|
||||
)?;
|
||||
|
||||
info!("Settings saved.");
|
||||
info!("Settings saved to: {:#}", db_file_path.display());
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
|
|||
use crate::config::structs::SpeechToTextEngine;
|
||||
use crate::config::structs::WakeWordEngine;
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct Settings {
|
||||
pub microphone: i32,
|
||||
pub voice: String,
|
||||
|
|
@ -32,7 +32,7 @@ impl Default for Settings {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
pub struct ApiKeys {
|
||||
pub picovoice: String,
|
||||
pub openai: String,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
use once_cell::sync::{Lazy, OnceCell};
|
||||
use parking_lot::RwLock;
|
||||
use std::sync::Arc;
|
||||
use platform_dirs::AppDirs;
|
||||
use std::path::PathBuf;
|
||||
|
||||
|
|
@ -9,8 +11,13 @@ pub mod audio;
|
|||
pub mod commands;
|
||||
pub mod config;
|
||||
pub mod db;
|
||||
|
||||
#[cfg(feature = "jarvis_app")]
|
||||
pub mod listener;
|
||||
|
||||
pub mod recorder;
|
||||
|
||||
#[cfg(feature = "jarvis_app")]
|
||||
pub mod stt;
|
||||
|
||||
// shared statics
|
||||
|
|
@ -19,7 +26,7 @@ pub static SOUND_DIR: Lazy<PathBuf> = Lazy::new(|| APP_DIR.clone().join("sound")
|
|||
pub static APP_DIRS: OnceCell<AppDirs> = OnceCell::new();
|
||||
pub static APP_CONFIG_DIR: OnceCell<PathBuf> = OnceCell::new();
|
||||
pub static APP_LOG_DIR: OnceCell<PathBuf> = OnceCell::new();
|
||||
pub static DB: OnceCell<db::structs::Settings> = OnceCell::new();
|
||||
pub static DB: OnceCell<Arc<RwLock<db::structs::Settings>>> = OnceCell::new();
|
||||
pub static COMMANDS_LIST: OnceCell<Vec<commands::AssistantCommand>> = OnceCell::new();
|
||||
|
||||
// re-exports
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
mod pvrecorder;
|
||||
|
||||
// mod cpal;
|
||||
// mod portaudio;
|
||||
|
||||
|
|
@ -122,29 +123,37 @@ pub fn stop_recording() -> Result<(), ()> {
|
|||
}
|
||||
|
||||
pub fn get_selected_microphone_index() -> i32 {
|
||||
DB.get().unwrap().microphone
|
||||
DB.get().unwrap().read().microphone
|
||||
}
|
||||
|
||||
pub fn get_audio_devices() -> Vec<String> {
|
||||
match RECORDER_TYPE.get().unwrap() {
|
||||
RecorderType::PvRecorder => pvrecorder::list_audio_devices(),
|
||||
RecorderType::PortAudio => {
|
||||
match RECORDER_TYPE.get() {
|
||||
Some(RecorderType::PvRecorder) => pvrecorder::list_audio_devices(),
|
||||
Some(RecorderType::PortAudio) => {
|
||||
todo!();
|
||||
}
|
||||
RecorderType::Cpal => {
|
||||
Some(RecorderType::Cpal) => {
|
||||
todo!();
|
||||
}
|
||||
None => {
|
||||
// not initialized yet, default to pvrecorder
|
||||
pvrecorder::list_audio_devices()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_audio_device_name(idx: i32) -> String {
|
||||
match RECORDER_TYPE.get().unwrap() {
|
||||
RecorderType::PvRecorder => pvrecorder::get_audio_device_name(idx),
|
||||
RecorderType::PortAudio => {
|
||||
match RECORDER_TYPE.get() {
|
||||
Some(RecorderType::PvRecorder) => pvrecorder::get_audio_device_name(idx),
|
||||
Some(RecorderType::PortAudio) => {
|
||||
todo!();
|
||||
}
|
||||
RecorderType::Cpal => {
|
||||
Some(RecorderType::Cpal) => {
|
||||
todo!();
|
||||
}
|
||||
None => {
|
||||
// not initialized yet, default to pvrecorder
|
||||
pvrecorder::get_audio_device_name(idx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
#[cfg(feature = "vosk")]
|
||||
mod vosk;
|
||||
|
||||
use crate::config;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue