mirror of
https://github.com/ndarilek/tts-rs.git
synced 2024-11-17 12:39:36 +00:00
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]
|
||||
tolk = "0.2"
|
||||
winrt = "0.7"
|
||||
winrt_bindings = {path="winrt_bindings"}
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
speech-dispatcher = "0.4"
|
||||
|
|
|
@ -1,21 +1,11 @@
|
|||
#[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 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,
|
||||
};
|
||||
use windows::media::speech_synthesis::SpeechSynthesizer;
|
||||
use winrt_bindings::windows::media::speech_synthesis::SpeechSynthesizer;
|
||||
|
||||
use crate::{Backend, Error, Features};
|
||||
|
||||
|
@ -35,6 +25,7 @@ impl WinRT {
|
|||
pub fn new() -> std::result::Result<Self, Error> {
|
||||
info!("Initializing WinRT backend");
|
||||
let player = MediaPlayer::new()?;
|
||||
player.set_auto_play(true)?;
|
||||
let playback_list = MediaPlaybackList::new()?;
|
||||
player.set_source(&playback_list)?;
|
||||
Ok(Self {
|
||||
|
@ -147,7 +138,7 @@ impl Backend for WinRT {
|
|||
|
||||
fn is_speaking(&self) -> std::result::Result<bool, Error> {
|
||||
let state = self.player.playback_session()?.playback_state()?;
|
||||
let playing = state == MediaPlaybackState::Playing;
|
||||
let playing = state == MediaPlaybackState::Opening || state == MediaPlaybackState::Playing;
|
||||
Ok(playing)
|
||||
}
|
||||
}
|
||||
|
|
11
winrt_bindings/Cargo.toml
Normal file
11
winrt_bindings/Cargo.toml
Normal file
|
@ -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"
|
12
winrt_bindings/build.rs
Normal file
12
winrt_bindings/build.rs
Normal file
|
@ -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();
|
||||
}
|
1
winrt_bindings/src/lib.rs
Normal file
1
winrt_bindings/src/lib.rs
Normal file
|
@ -0,0 +1 @@
|
|||
include!(concat!(env!("OUT_DIR"), "/winrt.rs"));
|
Loading…
Reference in New Issue
Block a user