mirror of
https://github.com/ndarilek/tts-rs.git
synced 2024-11-17 09:09:38 +00:00
Implement framework for utterance callbacks in Windows backends, though they aren't currently called.
This commit is contained in:
parent
61522610cd
commit
6788277a4d
|
@ -2,7 +2,7 @@
|
|||
use log::{info, trace};
|
||||
use tolk::Tolk as TolkPtr;
|
||||
|
||||
use crate::{Backend, Error, Features, UtteranceId};
|
||||
use crate::{Backend, BackendId, Error, Features, UtteranceId};
|
||||
|
||||
pub struct Tolk(TolkPtr);
|
||||
|
||||
|
@ -19,6 +19,10 @@ impl Tolk {
|
|||
}
|
||||
|
||||
impl Backend for Tolk {
|
||||
fn id(&self) -> Option<BackendId> {
|
||||
None
|
||||
}
|
||||
|
||||
fn supported_features(&self) -> Features {
|
||||
Features {
|
||||
stop: true,
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
#[cfg(windows)]
|
||||
use std::sync::Mutex;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use log::{info, trace};
|
||||
|
||||
use tts_winrt_bindings::windows::media::core::MediaSource;
|
||||
|
@ -7,7 +10,7 @@ use tts_winrt_bindings::windows::media::playback::{
|
|||
};
|
||||
use tts_winrt_bindings::windows::media::speech_synthesis::SpeechSynthesizer;
|
||||
|
||||
use crate::{Backend, Error, Features, UtteranceId};
|
||||
use crate::{Backend, BackendId, Error, Features, UtteranceId};
|
||||
|
||||
impl From<winrt::Error> for Error {
|
||||
fn from(e: winrt::Error) -> Self {
|
||||
|
@ -16,11 +19,16 @@ impl From<winrt::Error> for Error {
|
|||
}
|
||||
|
||||
pub struct WinRT {
|
||||
id: BackendId,
|
||||
synth: SpeechSynthesizer,
|
||||
player: MediaPlayer,
|
||||
playback_list: MediaPlaybackList,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
static ref NEXT_BACKEND_ID: Mutex<u64> = Mutex::new(0);
|
||||
}
|
||||
|
||||
impl WinRT {
|
||||
pub fn new() -> std::result::Result<Self, Error> {
|
||||
info!("Initializing WinRT backend");
|
||||
|
@ -28,11 +36,15 @@ impl WinRT {
|
|||
let player = MediaPlayer::new()?;
|
||||
player.set_auto_play(true)?;
|
||||
player.set_source(&playback_list)?;
|
||||
Ok(Self {
|
||||
let mut backend_id = NEXT_BACKEND_ID.lock().unwrap();
|
||||
let rv = Ok(Self {
|
||||
id: BackendId::WinRT(*backend_id),
|
||||
synth: SpeechSynthesizer::new()?,
|
||||
player: player,
|
||||
playback_list: playback_list,
|
||||
})
|
||||
});
|
||||
*backend_id += 1;
|
||||
rv
|
||||
}
|
||||
|
||||
fn reinit_player(&mut self) -> std::result::Result<(), Error> {
|
||||
|
@ -45,6 +57,10 @@ impl WinRT {
|
|||
}
|
||||
|
||||
impl Backend for WinRT {
|
||||
fn id(&self) -> Option<BackendId> {
|
||||
Some(self.id)
|
||||
}
|
||||
|
||||
fn supported_features(&self) -> Features {
|
||||
Features {
|
||||
stop: true,
|
||||
|
@ -52,6 +68,7 @@ impl Backend for WinRT {
|
|||
pitch: true,
|
||||
volume: true,
|
||||
is_speaking: true,
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,14 +46,14 @@ pub enum Backends {
|
|||
AvFoundation,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum BackendId {
|
||||
#[cfg(target_os = "linux")]
|
||||
SpeechDispatcher(u64),
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
Web(u64),
|
||||
#[cfg(windows)]
|
||||
WinRT(MediaPlaybackItem),
|
||||
WinRT(u64),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
|
|
Loading…
Reference in New Issue
Block a user