Change TEXT to INTEGER in card_stats
This commit is contained in:
1 parent
e8c9e37ca1
commit
1406fc8f21
5 files changed
+43
-34
No files matched your search
+17
-9
@@ -25,7 +25,7 @@ pub struct RepetitionState {
|
||||
current_statistic: CardStatistics,
|
||||
open: bool,
|
||||
can_play: bool,
|
||||
sink: Arc<MixerDeviceSink>,
|
||||
sink: Arc<Option<MixerDeviceSink>>,
|
||||
opened: HashSet<Id>,
|
||||
}
|
||||
|
||||
@@ -100,7 +100,12 @@ impl RepetitionState {
|
||||
pub(crate) fn new(set: DeckSettings, state: Arc<Mutex<AppState>>) -> RepetitionState {
|
||||
let mut card_set = DeckData::new(&set, state.clone());
|
||||
let (word, stat) = card_set.next();
|
||||
let sink_handle = rodio::DeviceSinkBuilder::open_default_sink().unwrap();
|
||||
|
||||
let sink_handle = if set.forward.contains("speech") || set.backward.contains("speech") {
|
||||
rodio::DeviceSinkBuilder::open_default_sink().ok()
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
RepetitionState {
|
||||
state,
|
||||
@@ -138,11 +143,12 @@ impl RepetitionState {
|
||||
self.current_word = next.0;
|
||||
self.current_statistic = next.1;
|
||||
|
||||
if self.settings.require_speech() {
|
||||
return Task::perform(
|
||||
play_sound(self.sink.clone(), self.current_word.key.clone()),
|
||||
|_| RootMessage::Repetition(RepetitionMessage::PlayFinished),
|
||||
);
|
||||
if self.settings.require_speech() && self.sink.is_some() {
|
||||
let sink = self.sink.clone();
|
||||
let task = play_sound(sink, self.current_word.key.clone());
|
||||
return Task::perform(task, |_| {
|
||||
RootMessage::Repetition(RepetitionMessage::PlayFinished)
|
||||
});
|
||||
}
|
||||
self.increment_counter();
|
||||
Task::none()
|
||||
@@ -316,10 +322,12 @@ pub enum RepetitionMessage {
|
||||
PlayFinished,
|
||||
}
|
||||
|
||||
async fn play_sound(sink: Arc<MixerDeviceSink>, text: String) {
|
||||
async fn play_sound(sink: Arc<Option<MixerDeviceSink>>, text: String) {
|
||||
if let Ok(data) = get_voice(text.as_str()).await {
|
||||
spawn_blocking(move || {
|
||||
if let Ok(play) = rodio::play(sink.mixer(), data) {
|
||||
if let Some(sink) = sink.as_ref()
|
||||
&& let Ok(play) = rodio::play(sink.mixer(), data)
|
||||
{
|
||||
play.sleep_until_end()
|
||||
}
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user