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 17 additions and 29 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::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();
path.push("voice");
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())));
path.push(hash);
@@ -20,21 +20,19 @@ pub async fn get_voice(text: &str) -> BufReader<File> {
.send()
.await;
let query = query.unwrap().text().await.unwrap();
let query = query.map_err(|_|())?.text().await.map_err(|_|())?;
// Synthesis
let audio = client
.post(format!("{engine_url}/synthesis?speaker=11"))
.header("Content-Type", "application/json")
.body(query)
.send()
.await
.unwrap()
.await.map_err(|_|())?
.bytes()
.await
.unwrap();
.await.map_err(|_|())?;
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])
.cloned()
.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 {
set: current_set,
@@ -515,7 +504,7 @@ impl SRSModule for RandomSRSModule {
fn init(&mut self, set: &mut DeckData) {
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())
}
}
+9 -8
View File
@@ -9,8 +9,8 @@ use chrono::Local;
use iced::alignment::Horizontal::Center;
use iced::keyboard::key::Physical::Code;
use iced::widget::text::Style;
use iced::widget::{Column, button, column, container, row, rule, space, text, tooltip};
use iced::{Element, Fill, Task, Theme, alignment, keyboard};
use iced::widget::{button, column, container, row, rule, space, text, tooltip, Column};
use iced::{alignment, keyboard, Element, Fill, Task, Theme};
use parking_lot::Mutex;
use rodio::MixerDeviceSink;
use std::collections::HashSet;
@@ -317,10 +317,11 @@ pub enum RepetitionMessage {
}
async fn play_sound(sink: Arc<MixerDeviceSink>, text: String) {
let data = get_voice(text.as_str()).await;
spawn_blocking(move || {
rodio::play(sink.mixer(), data).unwrap().sleep_until_end();
})
.await
.unwrap();
if let Ok(data) = get_voice(text.as_str()).await {
spawn_blocking(move || {
rodio::play(sink.mixer(), data).unwrap().sleep_until_end();
})
.await
.unwrap();
}
}