Skip to content

Commit

Permalink
Fix Linux build
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Nov 2, 2022
1 parent 6c16bff commit 36de5e6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions main/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "realearn"
version = "2.14.0-pre.8"
version = "2.14.0-pre.9"
authors = ["Benjamin Klum <[email protected]>"]
edition = "2021"
build = "build.rs"
Expand Down Expand Up @@ -169,8 +169,6 @@ device_query = "1.1.1"
egui-baseview = { git = "https://github.com/helgoboss/egui-baseview.git", branch = "feature/open-links-in-browser" }
baseview = { git = "https://github.com/helgoboss/baseview.git", branch = "try-borrow-mut" }
egui = "0.19.0"
# For speech source
tts = { git = "https://github.com/helgoboss/tts-rs", branch = "helgoboss-fixes" }
# For Pot target
rusqlite = { version = "0.28.0", features = ["bundled"] }
# For Pot target
Expand All @@ -182,6 +180,10 @@ rmp-serde = "1.1.1"
# For Pot target (NKS)
dirs = "4.0.0"

[target.'cfg(any(target_os = "windows", target_os = "macos"))'.dependencies]
# For speech source
tts = { git = "https://github.com/helgoboss/tts-rs", branch = "helgoboss-fixes" }

[target.'cfg(windows)'.dependencies]
# For detecting the Windows version (to determine whether special charactes can be displayed)
sys-info = "0.7"
Expand Down
64 changes: 33 additions & 31 deletions main/src/domain/reaper_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use std::error::Error;
use std::fmt::{Display, Formatter};
use std::sync::Mutex;
use std::time::{Duration, Instant};
use tts::Tts;

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

pub fn say(feedback_value: SpeechSourceFeedbackValue) -> Result<(), Box<dyn Error>> {
use once_cell::sync::Lazy;
static TTS: Lazy<Result<Mutex<Tts>, tts::Error>> =
Lazy::new(|| get_default_tts().map(Mutex::new));
let tts = TTS.as_ref()?;
// TODO-medium This is only necessary because tts exposes a non-optimal API.
let mut tts = tts.lock()?;
// TODO-medium This cloning is totally unnecessary but ... non-optimal API.
tts.speak(feedback_value.text, true)?;
Ok(())
}

fn get_default_tts() -> Result<Tts, tts::Error> {
#[cfg(target_os = "macos")]
#[cfg(any(target_os = "windows", target_os = "macos"))]
{
let mut tts = Tts::default()?;
// On macOS, at least with AVFoundation, it's necessary to set a voice first.
// Prefer an English voice as default.
if let Ok(voices) = tts.voices() {
let voice = voices
.iter()
.find(|v| v.language().language.as_str() == "en")
.or_else(|| voices.first());
if let Some(v) = voice {
tts.set_voice(v)?;
fn get_default_tts() -> Result<tts::Tts, tts::Error> {
#[cfg(target_os = "macos")]
{
let mut tts = tts::Tts::default()?;
// On macOS, at least with AVFoundation, it's necessary to set a voice first.
// Prefer an English voice as default.
if let Ok(voices) = tts.voices() {
let voice = voices
.iter()
.find(|v| v.language().language.as_str() == "en")
.or_else(|| voices.first());
if let Some(v) = voice {
tts.set_voice(v)?;
}
}
Ok(tts)
}
#[cfg(target_os = "windows")]
{
Tts::default()
}
}
Ok(tts)
}
#[cfg(target_os = "windows")]
{
Tts::default()

use once_cell::sync::Lazy;
static TTS: Lazy<Result<Mutex<tts::Tts>, tts::Error>> =
Lazy::new(|| get_default_tts().map(Mutex::new));
let tts = TTS.as_ref()?;
// TODO-medium This is only necessary because tts exposes a non-optimal API.
let mut tts = tts.lock()?;
// TODO-medium This cloning is totally unnecessary but ... non-optimal API.
tts.speak(feedback_value.text, true)?;
Ok(())
}
#[cfg(target_os = "linux")]
{
// Too buggy on Linux at the moment (crashes)
Err(tts::Error::UnsupportedFeature)
let _ = feedback_value;
Err("not yet supported on Linux")
}
}

Expand Down

0 comments on commit 36de5e6

Please sign in to comment.