@@ -12,7 +12,6 @@ use std::error::Error;
12
12
use std:: fmt:: { Display , Formatter } ;
13
13
use std:: sync:: Mutex ;
14
14
use std:: time:: { Duration , Instant } ;
15
- use tts:: Tts ;
16
15
17
16
#[ derive( Clone , Eq , PartialEq , Debug ) ]
18
17
pub enum ReaperSource {
@@ -39,42 +38,45 @@ impl SpeechSource {
39
38
}
40
39
41
40
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" ) ) ]
55
42
{
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 ( )
66
63
}
67
64
}
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 ( ( ) )
73
75
}
74
76
#[ cfg( target_os = "linux" ) ]
75
77
{
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" )
78
80
}
79
81
}
80
82
0 commit comments