Skip to content

Commit 36de5e6

Browse files
committed
Fix Linux build
1 parent 6c16bff commit 36de5e6

File tree

3 files changed

+39
-35
lines changed

3 files changed

+39
-35
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

main/Cargo.toml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "realearn"
3-
version = "2.14.0-pre.8"
3+
version = "2.14.0-pre.9"
44
authors = ["Benjamin Klum <[email protected]>"]
55
edition = "2021"
66
build = "build.rs"
@@ -169,8 +169,6 @@ device_query = "1.1.1"
169169
egui-baseview = { git = "https://github.com/helgoboss/egui-baseview.git", branch = "feature/open-links-in-browser" }
170170
baseview = { git = "https://github.com/helgoboss/baseview.git", branch = "try-borrow-mut" }
171171
egui = "0.19.0"
172-
# For speech source
173-
tts = { git = "https://github.com/helgoboss/tts-rs", branch = "helgoboss-fixes" }
174172
# For Pot target
175173
rusqlite = { version = "0.28.0", features = ["bundled"] }
176174
# For Pot target
@@ -182,6 +180,10 @@ rmp-serde = "1.1.1"
182180
# For Pot target (NKS)
183181
dirs = "4.0.0"
184182

183+
[target.'cfg(any(target_os = "windows", target_os = "macos"))'.dependencies]
184+
# For speech source
185+
tts = { git = "https://github.com/helgoboss/tts-rs", branch = "helgoboss-fixes" }
186+
185187
[target.'cfg(windows)'.dependencies]
186188
# For detecting the Windows version (to determine whether special charactes can be displayed)
187189
sys-info = "0.7"

main/src/domain/reaper_source.rs

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use std::error::Error;
1212
use std::fmt::{Display, Formatter};
1313
use std::sync::Mutex;
1414
use std::time::{Duration, Instant};
15-
use tts::Tts;
1615

1716
#[derive(Clone, Eq, PartialEq, Debug)]
1817
pub enum ReaperSource {
@@ -39,42 +38,45 @@ impl SpeechSource {
3938
}
4039

4140
pub fn say(feedback_value: SpeechSourceFeedbackValue) -> Result<(), Box<dyn Error>> {
42-
use once_cell::sync::Lazy;
43-
static TTS: Lazy<Result<Mutex<Tts>, tts::Error>> =
44-
Lazy::new(|| get_default_tts().map(Mutex::new));
45-
let tts = TTS.as_ref()?;
46-
// TODO-medium This is only necessary because tts exposes a non-optimal API.
47-
let mut tts = tts.lock()?;
48-
// TODO-medium This cloning is totally unnecessary but ... non-optimal API.
49-
tts.speak(feedback_value.text, true)?;
50-
Ok(())
51-
}
52-
53-
fn get_default_tts() -> Result<Tts, tts::Error> {
54-
#[cfg(target_os = "macos")]
41+
#[cfg(any(target_os = "windows", target_os = "macos"))]
5542
{
56-
let mut tts = Tts::default()?;
57-
// On macOS, at least with AVFoundation, it's necessary to set a voice first.
58-
// Prefer an English voice as default.
59-
if let Ok(voices) = tts.voices() {
60-
let voice = voices
61-
.iter()
62-
.find(|v| v.language().language.as_str() == "en")
63-
.or_else(|| voices.first());
64-
if let Some(v) = voice {
65-
tts.set_voice(v)?;
43+
fn get_default_tts() -> Result<tts::Tts, tts::Error> {
44+
#[cfg(target_os = "macos")]
45+
{
46+
let mut tts = tts::Tts::default()?;
47+
// On macOS, at least with AVFoundation, it's necessary to set a voice first.
48+
// Prefer an English voice as default.
49+
if let Ok(voices) = tts.voices() {
50+
let voice = voices
51+
.iter()
52+
.find(|v| v.language().language.as_str() == "en")
53+
.or_else(|| voices.first());
54+
if let Some(v) = voice {
55+
tts.set_voice(v)?;
56+
}
57+
}
58+
Ok(tts)
59+
}
60+
#[cfg(target_os = "windows")]
61+
{
62+
Tts::default()
6663
}
6764
}
68-
Ok(tts)
69-
}
70-
#[cfg(target_os = "windows")]
71-
{
72-
Tts::default()
65+
66+
use once_cell::sync::Lazy;
67+
static TTS: Lazy<Result<Mutex<tts::Tts>, tts::Error>> =
68+
Lazy::new(|| get_default_tts().map(Mutex::new));
69+
let tts = TTS.as_ref()?;
70+
// TODO-medium This is only necessary because tts exposes a non-optimal API.
71+
let mut tts = tts.lock()?;
72+
// TODO-medium This cloning is totally unnecessary but ... non-optimal API.
73+
tts.speak(feedback_value.text, true)?;
74+
Ok(())
7375
}
7476
#[cfg(target_os = "linux")]
7577
{
76-
// Too buggy on Linux at the moment (crashes)
77-
Err(tts::Error::UnsupportedFeature)
78+
let _ = feedback_value;
79+
Err("not yet supported on Linux")
7880
}
7981
}
8082

0 commit comments

Comments
 (0)