mirror of https://github.com/ndarilek/tts-rs.git
Various WinRT refinements.
* Move autogenerated code to subcrate to speed up compilation. * `is_speaking` also checks whether a source is opening, in addition to whether it is playing. * Return to using autoplay.
This commit is contained in:
parent
843bf876c1
commit
45c7b1afc7
|
@ -18,6 +18,7 @@ env_logger = "0.7"
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
tolk = "0.2"
|
tolk = "0.2"
|
||||||
winrt = "0.7"
|
winrt = "0.7"
|
||||||
|
winrt_bindings = {path="winrt_bindings"}
|
||||||
|
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
speech-dispatcher = "0.4"
|
speech-dispatcher = "0.4"
|
||||||
|
|
|
@ -1,21 +1,11 @@
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use winrt::*;
|
|
||||||
|
|
||||||
import!(
|
|
||||||
dependencies
|
|
||||||
os
|
|
||||||
types
|
|
||||||
windows::media::core::MediaSource
|
|
||||||
windows::media::playback::{MediaPlaybackItem, MediaPlaybackList, MediaPlaybackState, MediaPlayer}
|
|
||||||
windows::media::speech_synthesis::SpeechSynthesizer
|
|
||||||
);
|
|
||||||
|
|
||||||
use log::{info, trace};
|
use log::{info, trace};
|
||||||
use windows::media::core::MediaSource;
|
|
||||||
use windows::media::playback::{
|
use winrt_bindings::windows::media::core::MediaSource;
|
||||||
|
use winrt_bindings::windows::media::playback::{
|
||||||
MediaPlaybackItem, MediaPlaybackList, MediaPlaybackState, MediaPlayer,
|
MediaPlaybackItem, MediaPlaybackList, MediaPlaybackState, MediaPlayer,
|
||||||
};
|
};
|
||||||
use windows::media::speech_synthesis::SpeechSynthesizer;
|
use winrt_bindings::windows::media::speech_synthesis::SpeechSynthesizer;
|
||||||
|
|
||||||
use crate::{Backend, Error, Features};
|
use crate::{Backend, Error, Features};
|
||||||
|
|
||||||
|
@ -35,6 +25,7 @@ impl WinRT {
|
||||||
pub fn new() -> std::result::Result<Self, Error> {
|
pub fn new() -> std::result::Result<Self, Error> {
|
||||||
info!("Initializing WinRT backend");
|
info!("Initializing WinRT backend");
|
||||||
let player = MediaPlayer::new()?;
|
let player = MediaPlayer::new()?;
|
||||||
|
player.set_auto_play(true)?;
|
||||||
let playback_list = MediaPlaybackList::new()?;
|
let playback_list = MediaPlaybackList::new()?;
|
||||||
player.set_source(&playback_list)?;
|
player.set_source(&playback_list)?;
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
|
@ -147,7 +138,7 @@ impl Backend for WinRT {
|
||||||
|
|
||||||
fn is_speaking(&self) -> std::result::Result<bool, Error> {
|
fn is_speaking(&self) -> std::result::Result<bool, Error> {
|
||||||
let state = self.player.playback_session()?.playback_state()?;
|
let state = self.player.playback_session()?.playback_state()?;
|
||||||
let playing = state == MediaPlaybackState::Playing;
|
let playing = state == MediaPlaybackState::Opening || state == MediaPlaybackState::Playing;
|
||||||
Ok(playing)
|
Ok(playing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
[package]
|
||||||
|
name = "winrt_bindings"
|
||||||
|
version = "0.1.0"
|
||||||
|
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
|
||||||
|
edition = "2018"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
winrt = "0.7"
|
||||||
|
|
||||||
|
[build-dependencies]
|
||||||
|
winrt = "0.7"
|
|
@ -0,0 +1,12 @@
|
||||||
|
winrt::build!(
|
||||||
|
dependencies
|
||||||
|
os
|
||||||
|
types
|
||||||
|
windows::media::core::MediaSource
|
||||||
|
windows::media::playback::{MediaPlaybackItem, MediaPlaybackList, MediaPlaybackState, MediaPlayer}
|
||||||
|
windows::media::speech_synthesis::SpeechSynthesizer
|
||||||
|
);
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
build();
|
||||||
|
}
|
|
@ -0,0 +1 @@
|
||||||
|
include!(concat!(env!("OUT_DIR"), "/winrt.rs"));
|
Loading…
Reference in New Issue