Repetitions remake #1

Merged
micialware merged 30 commits from repetitions-remake into master 2026-08-20 19:48:19 +03:00
3 changed files with 12 additions and 24 deletions
Showing only changes of commit c5e91b844c - Show all commits

No files matched your search

+7 -9
View File
@@ -4,11 +4,11 @@ use sha2::{Digest, Sha256};
use std::fs::File; use std::fs::File;
use std::io::BufReader; use std::io::BufReader;
pub async fn get_voice(text: &str) -> BufReader<File> { pub async fn get_voice(text: &str) -> Result<BufReader<File>, ()> {
let mut path = app_data_dir(); let mut path = app_data_dir();
path.push("voice"); path.push("voice");
if !path.exists() { if !path.exists() {
std::fs::create_dir(path.clone()).unwrap(); std::fs::create_dir(path.clone()).map_err(|_|())?;
} }
let hash = format!("{}.wav", hex::encode(Sha256::digest(text.as_bytes()))); let hash = format!("{}.wav", hex::encode(Sha256::digest(text.as_bytes())));
path.push(hash); path.push(hash);
@@ -20,21 +20,19 @@ pub async fn get_voice(text: &str) -> BufReader<File> {
.send() .send()
.await; .await;
let query = query.unwrap().text().await.unwrap(); let query = query.map_err(|_|())?.text().await.map_err(|_|())?;
// Synthesis // Synthesis
let audio = client let audio = client
.post(format!("{engine_url}/synthesis?speaker=11")) .post(format!("{engine_url}/synthesis?speaker=11"))
.header("Content-Type", "application/json") .header("Content-Type", "application/json")
.body(query) .body(query)
.send() .send()
.await .await.map_err(|_|())?
.unwrap()
.bytes() .bytes()
.await .await.map_err(|_|())?;
.unwrap();
tokio::fs::write(&path, &audio).await.unwrap(); tokio::fs::write(&path, &audio).await.map_err(|_|())?;
} }
BufReader::new(File::open(path).unwrap()) Ok(BufReader::new(File::open(path).map_err(|_|())?))
} }
+1 -12
View File
@@ -364,17 +364,6 @@ impl DeckData {
.map(|w| &state_locked.dictionary[*w]) .map(|w| &state_locked.dictionary[*w])
.cloned() .cloned()
.collect(); .collect();
let word_ids = last_list.iter().map(|l| l.id).collect::<Vec<Id>>();
let mut index = 0;
for stat in current_set.clone() {
if !word_ids.contains(&stat.word_id) {
delete_stat(&stat, &state_locked.connection);
current_set.remove(index);
} else {
index += 1;
}
}
Self { Self {
set: current_set, set: current_set,
@@ -515,7 +504,7 @@ impl SRSModule for RandomSRSModule {
fn init(&mut self, set: &mut DeckData) { fn init(&mut self, set: &mut DeckData) {
self.initialized = true; self.initialized = true;
self.basket = (0..set.words.len()).collect::<Vec<usize>>(); self.basket = (0..set.set.len()).collect::<Vec<usize>>();
self.basket.shuffle(&mut rand::rng()) self.basket.shuffle(&mut rand::rng())
} }
} }
+4 -3
View File
@@ -9,8 +9,8 @@ use chrono::Local;
use iced::alignment::Horizontal::Center; use iced::alignment::Horizontal::Center;
use iced::keyboard::key::Physical::Code; use iced::keyboard::key::Physical::Code;
use iced::widget::text::Style; use iced::widget::text::Style;
use iced::widget::{Column, button, column, container, row, rule, space, text, tooltip}; use iced::widget::{button, column, container, row, rule, space, text, tooltip, Column};
use iced::{Element, Fill, Task, Theme, alignment, keyboard}; use iced::{alignment, keyboard, Element, Fill, Task, Theme};
use parking_lot::Mutex; use parking_lot::Mutex;
use rodio::MixerDeviceSink; use rodio::MixerDeviceSink;
use std::collections::HashSet; use std::collections::HashSet;
@@ -317,10 +317,11 @@ pub enum RepetitionMessage {
} }
async fn play_sound(sink: Arc<MixerDeviceSink>, text: String) { async fn play_sound(sink: Arc<MixerDeviceSink>, text: String) {
let data = get_voice(text.as_str()).await; if let Ok(data) = get_voice(text.as_str()).await {
spawn_blocking(move || { spawn_blocking(move || {
rodio::play(sink.mixer(), data).unwrap().sleep_until_end(); rodio::play(sink.mixer(), data).unwrap().sleep_until_end();
}) })
.await .await
.unwrap(); .unwrap();
}
} }