Compare commits

...

70 Commits

Author SHA1 Message Date
Nolan Darilek 3bc16f0c6f Bump version and windows dependency. 2024-04-19 09:17:08 -05:00
Nolan Darilek 3c8ae0ae42 Bump version. 2024-02-09 11:54:31 -06:00
Nolan Darilek 07edc20861 Switch `Arc` to `Rc` to appease Clippy. 2024-02-09 11:34:01 -06:00
Nolan Darilek 96a5209a9f Attempt to simplify CI. 2024-02-09 11:29:00 -06:00
Nolan Darilek 20b18949e2 Just build for target since we don't need an APK. 2024-02-09 11:07:11 -06:00
Nolan Darilek f29de0aede Switch to actions/checkout@v4. 2024-02-09 11:03:41 -06:00
Nolan Darilek 9e1476fd36
Merge pull request #49 from subalterngames:speech_dispatcher_voices_panic
Fixed a panic in SpeechDispatcher.voices()
2024-02-09 10:59:04 -06:00
Nolan Darilek 3032fe0fb3
Merge pull request #51 from Enyium:patch-1
Added docs.rs link to `Cargo.toml`
2024-02-09 10:54:59 -06:00
Nolan Darilek edd09c24e7 Switch from cargo-apk to xbuild. 2024-02-09 10:49:08 -06:00
Nolan Darilek b7b4e7dc85 Bump dependencies. 2024-02-09 10:37:55 -06:00
Nolan Darilek f593340051
Merge pull request #50 from MarijnS95:drop-ndk-glue
Drop `ndk-glue` dependency from the main crate
2024-02-09 10:31:54 -06:00
Enyium 12d8e1f532
Added docs.rs link to `Cargo.toml` 2023-12-05 12:28:47 +01:00
Marijn Suijten 2a81dc9b70 Drop `ndk-glue` dependency from the main crate
Commit d42d201 ("Update Android dependencies and example.") correctly
replaces `ndk-glue` with `ndk-context` as a more generic crate to hold on
to a global `JavaVM` and Android `jobject` `Context`, but didn't drop the
unused `ndk-glue` crate from the list of Android dependencies.  This
crate is only used in the example crate, and [shouldn't clobber
downstream crates].

Besides, `ndk-glue` has been deprecated for some time and should be
replaced by `android-activity` in the example in a followup PR.

[shouldn't clobber downstream crates]: https://github.com/emilk/egui/pull/3606/files#r1401313794
2023-11-22 00:12:48 +01:00
Esther Alter a0c6cbaf6a Fixed a panic in SpeechDispatcher.voices() 2023-10-25 11:59:13 -04:00
Nolan Darilek 5c528f1d8e Bump version. 2023-09-09 12:44:17 -05:00
Nolan Darilek 9fb8107acf Eliminate some warnings. 2023-09-09 12:43:43 -05:00
Nolan Darilek 8dabcc99c4 Bump windows dependency. 2023-09-09 12:41:36 -05:00
Nolan Darilek b369fb5614 docs.rs is actually using speech-dispatcher 0.11 now. 2023-04-06 10:19:21 -05:00
Nolan Darilek e6e1cd49bf Attempt to fix docs.rs builds and bump version. 2023-04-05 11:27:49 -05:00
Nolan Darilek e2edc18e6e Bump dependency and version. 2023-04-03 10:08:03 -05:00
Nolan Darilek 3eba940a22 Bump `windows` dependency and version. 2023-03-28 14:20:23 -05:00
Nolan Darilek 7e761e1267 Complete migration to jni 0.21. 2023-03-06 15:25:49 -06:00
Nolan Darilek bf8eb07866 Bump version. 2023-03-06 14:36:48 -06:00
Nolan Darilek f5be2b7657 Bump jni dependency. 2023-03-06 14:34:49 -06:00
Nolan Darilek b7e7ed46dd Appease Clippy. 2023-03-06 14:34:49 -06:00
Nolan Darilek 69eebf2ffa Bump windows dependency. 2023-03-06 14:34:49 -06:00
Nolan Darilek 6c6089daf9
Merge pull request #41 from ninjaboy:fix-macos-inline-play-example
Add support for inline pronounciation
2023-03-06 14:34:30 -06:00
Alexey Stolybko c874607afe Add support for inline pronounciation 2022-12-26 20:07:58 +00:00
Nolan Darilek 2667d4e943 Bump version. 2022-12-02 13:06:02 -06:00
Nolan Darilek 8b506a89e0 ... 2022-12-02 13:00:20 -06:00
Nolan Darilek dcaf5b914d ... 2022-12-02 12:59:33 -06:00
Nolan Darilek 359b1c8053 Obnoxious that I can't just push this directly to the mac and test for some reason... 2022-12-02 12:58:46 -06:00
Nolan Darilek 527b4cd61e Small tweaks. 2022-12-02 12:57:34 -06:00
Nolan Darilek 97fa370dec Refactor AVFoundation to oxilangtag. 2022-12-02 12:52:08 -06:00
Nolan Darilek 915673eec6 Bump dependency. 2022-12-02 12:38:50 -06:00
Nolan Darilek cf72bad59a cargo fmt 2022-11-22 15:44:09 -06:00
Nolan Darilek 246e587f2d Merge branch 'master' into oxilangtag 2022-11-22 15:38:04 -06:00
Nolan Darilek d65d79f8fb More tweaks and simplifications to work around ndk-sys checksum failure. 2022-11-22 15:16:18 -06:00
Nolan Darilek c339d2bee3 Bump editions in exampels, and remove unnecessary dependencies. 2022-11-22 14:55:31 -06:00
Nolan Darilek daaead1dc3 Tweak features used in CI builds. 2022-11-22 14:36:15 -06:00
Nolan Darilek d547d84af0 Merge branch 'master' into oxilangtag 2022-11-22 14:16:08 -06:00
Nolan Darilek f6766ec633 Bump speech-dispatcher dependency and tweak docs.rs build configuration. 2022-11-22 14:15:40 -06:00
Nolan Darilek 8102820f86 These checks should be run before the tag is pushed, so remove them from the release workflow. 2022-11-22 14:13:46 -06:00
Nolan Darilek 3c9a78a953 Install necessary targets and simplify further. 2022-11-22 12:44:43 -06:00
Nolan Darilek 5470b9557d Drop old actions-rs actions which seem to no longer be updated. 2022-11-22 12:36:00 -06:00
Nolan Darilek 6770a2ed58 Eliminate caching. 2022-11-22 12:27:40 -06:00
Nolan Darilek 61d84a2120 Manually install toolchain before cache to eliminate a deprecated action and hopefully fix checksum validation failures. 2022-11-22 12:12:57 -06:00
Nolan Darilek 7a91a1e827 Merge branch 'master' into android 2022-11-22 11:26:04 -06:00
Nolan Darilek e19e5ef0b7 Remove unnecessary return statement. 2022-11-22 11:13:05 -06:00
Nolan Darilek 3e4299d0e6 Update some old actions to newer versions. 2022-11-22 11:04:05 -06:00
Nolan Darilek d42d20189a Update Android dependencies and example. 2022-11-22 10:44:18 -06:00
Nolan Darilek 22ae0ef5a3 Refactor to oxilangtag for language codes, and bump Windows dependency. 2022-11-21 12:00:35 -06:00
Nolan Darilek f5716c48f5 Fix type mismatches after speech-dispatcher update. 2022-10-19 10:28:18 -05:00
Nolan Darilek eb1d13976a Bump version. 2022-10-19 09:58:45 -05:00
Nolan Darilek 259549e21d
Merge pull request #34 from helgoboss:master
#33 Fix AVFoundation crash on macOS when getting voices
2022-10-19 09:58:02 -05:00
Nolan Darilek 3679ad6153
Merge pull request #36 from helgoboss:bug/35-appkit-crash
#35 Fix AppKit crash when interrupting speech
2022-10-19 09:55:15 -05:00
Benjamin Klum 94615a254a #35 Fix AppKit crash when interrupting speech
avoid removing first string when queue already empty
2022-10-16 23:18:19 +02:00
Benjamin Klum ddf96c10aa #33 Remove unnecessary unsafe keyword 2022-10-16 23:15:52 +02:00
Benjamin Klum 3fdd452646 #33 Fix AVFoundation crash on macOS when getting voices
by preventing manual cleanup of non-owned objects
2022-10-16 22:35:03 +02:00
Nolan Darilek b4f48fa439 Bump dependency and version. 2022-10-03 16:59:33 -05:00
Nolan Darilek 919bc4249a Bump dependency and version. 2022-09-21 16:38:09 -05:00
Nolan Darilek 79e59d551f Remove unnecessary version pins. 2022-09-07 12:37:29 -05:00
Nolan Darilek 652367fa8a Build on Ubuntu 22.04. 2022-09-07 12:33:45 -05:00
Nolan Darilek 3c38c783b0 Support speech-dispatcher 0.11 and 0.10, dropping support for 0.9. 2022-09-07 12:33:33 -05:00
Nolan Darilek 1eae827ed1 Add support for speech-dispatcher 0.10.2 and bump version. 2022-08-29 16:50:49 -05:00
Nolan Darilek f404e180e4 Bump version. 2022-07-22 10:13:32 -05:00
Nolan Darilek 7cf80fb64d WinRT: Correctly set voice for case where no utterances are in queue.
Fixes #29
2022-07-22 10:08:13 -05:00
Nolan Darilek b50c5b6b93
Merge pull request #28 from Bear-03/traits
Derive common traits for Gender and Voice
2022-07-22 09:57:49 -05:00
Nolan Darilek 748f07138d Bump version and dependency. 2022-07-21 18:34:22 -05:00
Bear-03 15f28c9af4
Derive common traits for Gender and Voice 2022-07-21 01:25:14 +02:00
18 changed files with 243 additions and 321 deletions

View File

@ -6,98 +6,16 @@ on:
- "v*"
jobs:
check:
name: Check
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- run: sudo apt-get update; sudo apt-get install -y libspeechd-dev
if: ${{ runner.os == 'Linux' }}
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt, clippy
override: true
- uses: actions-rs/cargo@v1
with:
command: check
args: --all-features --examples
if: ${{ runner.os != 'Linux' }}
- uses: actions-rs/cargo@v1
with:
command: check
args: --no-default-features --examples
if: ${{ runner.os == 'Linux' }}
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all --check
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
if: ${{ runner.os != 'Linux' }}
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --no-default-features
if: ${{ runner.os == 'Linux' }}
check_web:
name: Check Web
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- uses: actions-rs/toolchain@v1
with:
target: wasm32-unknown-unknown
profile: minimal
toolchain: stable
components: rustfmt, clippy
override: true
- uses: actions-rs/cargo@v1
with:
command: check
args: --all-features --examples --target wasm32-unknown-unknown
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --target wasm32-unknown-unknown
- uses: actions-rs/install@v0.1
with:
crate: cargo-make
- uses: actions-rs/cargo@v1
with:
command: make
args: build-web-example
publish:
name: Publish
runs-on: ubuntu-latest
needs: [check, check_web]
runs-on: ubuntu-22.04
env:
CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }}
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- uses: actions-rs/toolchain@v1
with:
target: wasm32-unknown-unknown
profile: minimal
toolchain: stable
override: true
- uses: actions/checkout@v4
- run: |
sudo apt-get update
sudo apt-get install -y libspeechd-dev
cargo login $CARGO_TOKEN
cargo publish --no-default-features
rustup toolchain install stable
cargo publish

View File

@ -5,113 +5,58 @@ on:
pull_request:
jobs:
check_formatting:
name: Check Formatting
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
- run: |
rustup toolchain install stable
cargo fmt --all --check
cd examples/web
cargo fmt --all --check
check:
name: Check
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
os: [windows-latest, ubuntu-22.04, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- uses: actions/checkout@v4
- run: sudo apt-get update; sudo apt-get install -y libspeechd-dev
if: ${{ runner.os == 'Linux' }}
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt, clippy
override: true
- uses: actions-rs/cargo@v1
with:
command: check
args: --all-features --examples
if: ${{ runner.os != 'Linux' }}
- uses: actions-rs/cargo@v1
with:
command: check
args: --no-default-features --examples
if: ${{ runner.os == 'Linux' }}
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all --check
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features
if: ${{ runner.os != 'Linux' }}
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --no-default-features
if: ${{ runner.os == 'Linux' }}
- run: |
rustup toolchain install stable
cargo clippy --all-targets
check_web:
name: Check Web
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- uses: actions-rs/toolchain@v1
with:
target: wasm32-unknown-unknown
profile: minimal
toolchain: stable
components: rustfmt, clippy
override: true
- uses: actions-rs/cargo@v1
with:
command: check
args: --all-features --examples --target wasm32-unknown-unknown
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all --check
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --target wasm32-unknown-unknown
- uses: actions/checkout@v4
- run: |
rustup target add wasm32-unknown-unknown
rustup toolchain install stable
cargo clippy --all-targets --target wasm32-unknown-unknown
check_android:
name: Check Android
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
components: rustfmt, clippy
override: true
- uses: actions-rs/install@v0.1
with:
crate: cargo-apk
# use-tool-cache: true
- run: rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
- uses: actions-rs/cargo@v1
with:
command: apk
args: build
- uses: actions/checkout@v4
- run: |
rustup target add aarch64-linux-android
rustup toolchain install stable
cargo clippy --all-targets --target aarch64-linux-android
check_web_example:
name: Check Web Example
runs-on: ubuntu-latest
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- uses: actions-rs/toolchain@v1
with:
target: wasm32-unknown-unknown
profile: minimal
toolchain: stable
components: rustfmt, clippy
override: true
- uses: actions-rs/install@v0.1
with:
crate: cargo-make
- uses: actions-rs/cargo@v1
with:
command: make
args: build-web-example
- uses: actions/checkout@v4
- run: |
rustup target add wasm32-unknown-unknown
rustup toolchain install stable
cd examples/web
cargo build --target wasm32-unknown-unknown

View File

@ -1,9 +1,10 @@
[package]
name = "tts"
version = "0.22.4"
version = "0.26.1"
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
repository = "https://github.com/ndarilek/tts-rs"
description = "High-level Text-To-Speech (TTS) interface"
documentation = "https://docs.rs/tts"
license = "MIT"
exclude = ["*.cfg", "*.yml"]
edition = "2021"
@ -12,26 +13,35 @@ edition = "2021"
crate-type = ["lib", "cdylib", "staticlib"]
[features]
speech_dispatcher_0_9 = ["speech-dispatcher/0_9"]
speech_dispatcher_0_10 = ["speech-dispatcher/0_10"]
default = ["speech_dispatcher_0_10"]
speech_dispatcher_0_11 = ["speech-dispatcher/0_11"]
default = ["speech_dispatcher_0_11"]
[dependencies]
dyn-clonable = "0.9"
oxilangtag = "0.1"
lazy_static = "1"
log = "0.4"
serde = { version = "1", optional = true, features = ["derive"] }
thiserror = "1"
unic-langid = "0.9.0"
serde = { version = "1.0", optional = true, features = ["derive"] }
[dev-dependencies]
env_logger = "0.9"
env_logger = "0.11"
[target.'cfg(windows)'.dependencies]
tolk = { version = "0.5", optional = true }
windows = { version = "0.38", features = ["alloc", "Foundation", "Foundation_Collections", "Media_Core", "Media_Playback", "Media_SpeechSynthesis", "Storage_Streams"] }
windows = { version = "0.56", features = [
"Foundation",
"Foundation_Collections",
"Media_Core",
"Media_Playback",
"Media_SpeechSynthesis",
"Storage_Streams",
] }
[target.'cfg(target_os = "linux")'.dependencies]
speech-dispatcher = { version = "0.13", default-features = false }
speech-dispatcher = { version = "0.16", default-features = false }
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
cocoa-foundation = "0.1"
@ -41,11 +51,21 @@ objc = { version = "0.2", features = ["exception"] }
[target.wasm32-unknown-unknown.dependencies]
wasm-bindgen = "0.2"
web-sys = { version = "0.3", features = ["EventTarget", "SpeechSynthesis", "SpeechSynthesisErrorCode", "SpeechSynthesisErrorEvent", "SpeechSynthesisEvent", "SpeechSynthesisUtterance", "SpeechSynthesisVoice", "Window", ] }
web-sys = { version = "0.3", features = [
"EventTarget",
"SpeechSynthesis",
"SpeechSynthesisErrorCode",
"SpeechSynthesisErrorEvent",
"SpeechSynthesisEvent",
"SpeechSynthesisUtterance",
"SpeechSynthesisVoice",
"Window",
] }
[target.'cfg(target_os="android")'.dependencies]
jni = "0.19"
ndk-glue = "0.6"
jni = "0.21"
ndk-context = "0.1"
[package.metadata.docs.rs]
no-default-features = true
no-default-features = true
features = ["speech_dispatcher_0_11"]

View File

@ -1,16 +1,16 @@
plugins {
id "com.android.application"
id "kotlin-android"
id "org.mozilla.rust-android-gradle.rust-android"
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
namespace "rs.tts"
compileSdkVersion 33
ndkVersion "25.1.8937393"
defaultConfig {
applicationId "rs.tts"
minSdkVersion 21
targetSdkVersion 30
targetSdkVersion 33
versionCode 1
versionName "1.0"
}
@ -21,27 +21,27 @@ android {
proguardFiles getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "androidx.core:core-ktx:1.2.0"
implementation "androidx.annotation:annotation:1.1.0"
implementation "com.google.android.material:material:1.1.0"
implementation "androidx.constraintlayout:constraintlayout:1.1.3"
}
apply plugin: "com.github.willir.rust.cargo-ndk-android"
apply plugin: "org.mozilla.rust-android-gradle.rust-android"
cargoNdk {
cargo {
module = "."
libname = "tts"
targets = ["arm", "x86"]
}
tasks.whenTaskAdded { task ->
if ((task.name == 'javaPreCompileDebug' || task.name == 'javaPreCompileRelease')) {
task.dependsOn "cargoBuild"
}
}
project.afterEvaluate {

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="rs.tts">
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
<application android:allowBackup="true" android:label="@string/app_name">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity" android:exported="true">
<meta-data android:name="android.app.lib_name" android:value="hello_world" />
<intent-filter>
<action android:name="android.intent.action.MAIN" />

View File

@ -1,28 +1,28 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72"
repositories {
google()
jcenter()
buildscript {
repositories {
google()
mavenCentral()
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath "com.android.tools.build:gradle:4.1.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "gradle.plugin.com.github.willir.rust:plugin:0.3.4"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
}
plugins {
id "com.android.application" version "7.3.0" apply false
id "com.android.library" version "7.3.0" apply false
id "org.jetbrains.kotlin.android" version "1.7.21" apply false
id "org.mozilla.rust-android-gradle.rust-android" version "0.9.3" apply false
}
allprojects {
repositories {
google()
jcenter()
}
}
mavenCentral()
}
}
task clean(type: Delete) {
delete rootProject.buildDir

View File

@ -2,7 +2,7 @@
name = "hello_world"
version = "0.1.0"
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
edition = "2018"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -10,5 +10,5 @@ edition = "2018"
crate-type = ["dylib"]
[dependencies]
ndk-glue = "0.6"
ndk-glue = "0.7"
tts = { path = "../.." }

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip

View File

@ -1 +1,8 @@
include ":app"
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
include ":app"

View File

@ -1,5 +1,14 @@
#[cfg(target_os = "macos")]
use cocoa_foundation::base::id;
#[cfg(target_os = "macos")]
use cocoa_foundation::foundation::NSDefaultRunLoopMode;
#[cfg(target_os = "macos")]
use cocoa_foundation::foundation::NSRunLoop;
#[cfg(target_os = "macos")]
use objc::class;
#[cfg(target_os = "macos")]
use objc::{msg_send, sel, sel_impl};
use std::{thread, time};
use tts::*;
fn main() -> Result<(), Error> {
@ -8,6 +17,14 @@ fn main() -> Result<(), Error> {
let mut phrase = 1;
loop {
tts.speak(format!("Phrase {}", phrase), false)?;
#[cfg(target_os = "macos")]
{
let run_loop: id = unsafe { NSRunLoop::currentRunLoop() };
unsafe {
let date: id = msg_send![class!(NSDate), distantFuture];
let _: () = msg_send![run_loop, runMode:NSDefaultRunLoopMode beforeDate:date];
}
}
let time = time::Duration::from_secs(5);
thread::sleep(time);
phrase += 1;

View File

@ -2,7 +2,7 @@
name = "web"
version = "0.1.0"
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
edition = "2018"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
@ -11,4 +11,3 @@ console_log = "0.2"
log = "0.4"
seed = "0.9"
tts = { path = "../.." }
wasm-bindgen = "= 0.2.80"

View File

@ -28,7 +28,7 @@ lazy_static! {
#[allow(non_snake_case)]
#[no_mangle]
pub extern "system" fn JNI_OnLoad(vm: JavaVM, _: *mut c_void) -> jint {
let env = vm.get_env().expect("Cannot get reference to the JNIEnv");
let mut env = vm.get_env().expect("Cannot get reference to the JNIEnv");
let b = env
.find_class("rs/tts/Bridge")
.expect("Failed to find `Bridge`");
@ -42,7 +42,7 @@ pub extern "system" fn JNI_OnLoad(vm: JavaVM, _: *mut c_void) -> jint {
#[no_mangle]
#[allow(non_snake_case)]
pub unsafe extern "C" fn Java_rs_tts_Bridge_onInit(env: JNIEnv, obj: JObject, status: jint) {
pub unsafe extern "C" fn Java_rs_tts_Bridge_onInit(mut env: JNIEnv, obj: JObject, status: jint) {
let id = env
.get_field(obj, "backendId", "I")
.expect("Failed to get backend ID")
@ -58,7 +58,7 @@ pub unsafe extern "C" fn Java_rs_tts_Bridge_onInit(env: JNIEnv, obj: JObject, st
#[no_mangle]
#[allow(non_snake_case)]
pub unsafe extern "C" fn Java_rs_tts_Bridge_onStart(
env: JNIEnv,
mut env: JNIEnv,
obj: JObject,
utterance_id: JString,
) {
@ -69,7 +69,7 @@ pub unsafe extern "C" fn Java_rs_tts_Bridge_onStart(
.expect("Failed to cast to int") as u64;
let backend_id = BackendId::Android(backend_id);
let utterance_id = CString::from(CStr::from_ptr(
env.get_string(utterance_id).unwrap().as_ptr(),
env.get_string(&utterance_id).unwrap().as_ptr(),
))
.into_string()
.unwrap();
@ -85,7 +85,7 @@ pub unsafe extern "C" fn Java_rs_tts_Bridge_onStart(
#[no_mangle]
#[allow(non_snake_case)]
pub unsafe extern "C" fn Java_rs_tts_Bridge_onStop(
env: JNIEnv,
mut env: JNIEnv,
obj: JObject,
utterance_id: JString,
) {
@ -96,7 +96,7 @@ pub unsafe extern "C" fn Java_rs_tts_Bridge_onStop(
.expect("Failed to cast to int") as u64;
let backend_id = BackendId::Android(backend_id);
let utterance_id = CString::from(CStr::from_ptr(
env.get_string(utterance_id).unwrap().as_ptr(),
env.get_string(&utterance_id).unwrap().as_ptr(),
))
.into_string()
.unwrap();
@ -112,7 +112,7 @@ pub unsafe extern "C" fn Java_rs_tts_Bridge_onStop(
#[no_mangle]
#[allow(non_snake_case)]
pub unsafe extern "C" fn Java_rs_tts_Bridge_onDone(
env: JNIEnv,
mut env: JNIEnv,
obj: JObject,
utterance_id: JString,
) {
@ -123,7 +123,7 @@ pub unsafe extern "C" fn Java_rs_tts_Bridge_onDone(
.expect("Failed to cast to int") as u64;
let backend_id = BackendId::Android(backend_id);
let utterance_id = CString::from(CStr::from_ptr(
env.get_string(utterance_id).unwrap().as_ptr(),
env.get_string(&utterance_id).unwrap().as_ptr(),
))
.into_string()
.unwrap();
@ -139,7 +139,7 @@ pub unsafe extern "C" fn Java_rs_tts_Bridge_onDone(
#[no_mangle]
#[allow(non_snake_case)]
pub unsafe extern "C" fn Java_rs_tts_Bridge_onError(
env: JNIEnv,
mut env: JNIEnv,
obj: JObject,
utterance_id: JString,
) {
@ -150,7 +150,7 @@ pub unsafe extern "C" fn Java_rs_tts_Bridge_onError(
.expect("Failed to cast to int") as u64;
let backend_id = BackendId::Android(backend_id);
let utterance_id = CString::from(CStr::from_ptr(
env.get_string(utterance_id).unwrap().as_ptr(),
env.get_string(&utterance_id).unwrap().as_ptr(),
))
.into_string()
.unwrap();
@ -179,22 +179,23 @@ impl Android {
let id = BackendId::Android(bid);
*backend_id += 1;
drop(backend_id);
let native_activity = ndk_glue::native_activity();
let vm = Self::vm()?;
let env = vm.attach_current_thread_permanently()?;
let ctx = ndk_context::android_context();
let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
let context = unsafe { JObject::from_raw(ctx.context().cast()) };
let mut env = vm.attach_current_thread_permanently()?;
let bridge = BRIDGE.lock().unwrap();
if let Some(bridge) = &*bridge {
let bridge = env.new_object(bridge, "(I)V", &[(bid as jint).into()])?;
let tts = env.new_object(
"android/speech/tts/TextToSpeech",
"(Landroid/content/Context;Landroid/speech/tts/TextToSpeech$OnInitListener;)V",
&[native_activity.activity().into(), bridge.into()],
&[(&context).into(), (&bridge).into()],
)?;
env.call_method(
tts,
&tts,
"setOnUtteranceProgressListener",
"(Landroid/speech/tts/UtteranceProgressListener;)I",
&[bridge.into()],
&[(&bridge).into()],
)?;
{
let mut pending = PENDING_INITIALIZATIONS.write().unwrap();
@ -229,9 +230,8 @@ impl Android {
}
fn vm() -> Result<JavaVM, jni::errors::Error> {
let native_activity = ndk_glue::native_activity();
let vm_ptr = native_activity.vm();
unsafe { jni::JavaVM::from_raw(vm_ptr) }
let ctx = ndk_context::android_context();
unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }
}
}
@ -255,7 +255,7 @@ impl Backend for Android {
fn speak(&mut self, text: &str, interrupt: bool) -> Result<Option<UtteranceId>, Error> {
let vm = Self::vm()?;
let env = vm.get_env()?;
let mut env = vm.get_env()?;
let tts = self.tts.as_obj();
let text = env.new_string(text)?;
let queue_mode = if interrupt { 0 } else { 1 };
@ -270,10 +270,10 @@ impl Backend for Android {
"speak",
"(Ljava/lang/CharSequence;ILandroid/os/Bundle;Ljava/lang/String;)I",
&[
text.into(),
(&text).into(),
queue_mode.into(),
JObject::null().into(),
uid.into(),
(&JObject::null()).into(),
(&uid).into(),
],
)?;
let rv = rv.i()?;
@ -286,7 +286,7 @@ impl Backend for Android {
fn stop(&mut self) -> Result<(), Error> {
let vm = Self::vm()?;
let env = vm.get_env()?;
let mut env = vm.get_env()?;
let tts = self.tts.as_obj();
let rv = env.call_method(tts, "stop", "()I", &[])?;
let rv = rv.i()?;
@ -315,7 +315,7 @@ impl Backend for Android {
fn set_rate(&mut self, rate: f32) -> Result<(), Error> {
let vm = Self::vm()?;
let env = vm.get_env()?;
let mut env = vm.get_env()?;
let tts = self.tts.as_obj();
let rate = rate as jfloat;
let rv = env.call_method(tts, "setSpeechRate", "(F)I", &[rate.into()])?;
@ -346,7 +346,7 @@ impl Backend for Android {
fn set_pitch(&mut self, pitch: f32) -> Result<(), Error> {
let vm = Self::vm()?;
let env = vm.get_env()?;
let mut env = vm.get_env()?;
let tts = self.tts.as_obj();
let pitch = pitch as jfloat;
let rv = env.call_method(tts, "setPitch", "(F)I", &[pitch.into()])?;
@ -381,7 +381,7 @@ impl Backend for Android {
fn is_speaking(&self) -> Result<bool, Error> {
let vm = Self::vm()?;
let env = vm.get_env()?;
let mut env = vm.get_env()?;
let tts = self.tts.as_obj();
let rv = env.call_method(tts, "isSpeaking", "()Z", &[])?;
let rv = rv.z()?;

View File

@ -46,13 +46,15 @@ impl AppKit {
) {
unsafe {
let strings: id = *this.get_ivar("strings");
let str: id = msg_send!(strings, firstObject);
let _: () = msg_send![str, release];
let _: () = msg_send!(strings, removeObjectAtIndex:0);
let count: u32 = msg_send![strings, count];
if count > 0 {
let str: id = msg_send!(strings, firstObject);
let _: BOOL = msg_send![synth, startSpeakingString: str];
let _: () = msg_send![str, release];
let _: () = msg_send!(strings, removeObjectAtIndex:0);
if count > 1 {
let str: id = msg_send!(strings, firstObject);
let _: BOOL = msg_send![synth, startSpeakingString: str];
}
}
}
}

View File

@ -1,15 +1,16 @@
#[cfg(any(target_os = "macos", target_os = "ios"))]
use std::{str::FromStr, sync::Mutex};
use std::sync::Mutex;
use cocoa_foundation::base::{id, nil, NO};
use cocoa_foundation::foundation::NSString;
use core_foundation::array::CFArray;
use core_foundation::base::TCFType;
use core_foundation::string::CFString;
use lazy_static::lazy_static;
use log::{info, trace};
use objc::runtime::{Object, Sel};
use objc::{class, declare::ClassDecl, msg_send, sel, sel_impl};
use unic_langid::LanguageIdentifier;
use oxilangtag::LanguageTag;
use crate::{Backend, BackendId, Error, Features, Gender, UtteranceId, Voice, CALLBACKS};
@ -290,21 +291,28 @@ impl Backend for AvFoundation {
}
fn voices(&self) -> Result<Vec<Voice>, Error> {
let voices: CFArray = unsafe { msg_send![class!(AVSpeechSynthesisVoice), speechVoices] };
let voices: CFArray = unsafe {
CFArray::wrap_under_get_rule(msg_send![class!(AVSpeechSynthesisVoice), speechVoices])
};
let rv = voices
.iter()
.map(|v| {
let id: CFString = unsafe { msg_send![*v as *const Object, identifier] };
let name: CFString = unsafe { msg_send![*v as *const Object, name] };
let id: CFString = unsafe {
CFString::wrap_under_get_rule(msg_send![*v as *const Object, identifier])
};
let name: CFString =
unsafe { CFString::wrap_under_get_rule(msg_send![*v as *const Object, name]) };
let gender: i64 = unsafe { msg_send![*v as *const Object, gender] };
let gender = match gender {
1 => Some(Gender::Male),
2 => Some(Gender::Female),
_ => None,
};
let language: CFString = unsafe { msg_send![*v as *const Object, language] };
let language: CFString = unsafe {
CFString::wrap_under_get_rule(msg_send![*v as *const Object, language])
};
let language = language.to_string();
let language = LanguageIdentifier::from_str(&language).unwrap();
let language = LanguageTag::parse(language).unwrap();
Voice {
id: id.to_string(),
name: name.to_string(),

View File

@ -1,10 +1,10 @@
#[cfg(target_os = "linux")]
use std::{collections::HashMap, str::FromStr, sync::Mutex};
use std::{collections::HashMap, sync::Mutex};
use lazy_static::*;
use log::{info, trace};
use oxilangtag::LanguageTag;
use speech_dispatcher::*;
use unic_langid::LanguageIdentifier;
use crate::{Backend, BackendId, Error, Features, UtteranceId, Voice, CALLBACKS};
@ -12,8 +12,8 @@ use crate::{Backend, BackendId, Error, Features, UtteranceId, Voice, CALLBACKS};
pub(crate) struct SpeechDispatcher(Connection);
lazy_static! {
static ref SPEAKING: Mutex<HashMap<u64, bool>> = {
let m: HashMap<u64, bool> = HashMap::new();
static ref SPEAKING: Mutex<HashMap<usize, bool>> = {
let m: HashMap<usize, bool> = HashMap::new();
Mutex::new(m)
};
}
@ -31,7 +31,7 @@ impl SpeechDispatcher {
let mut callbacks = CALLBACKS.lock().unwrap();
let backend_id = BackendId::SpeechDispatcher(client_id);
let cb = callbacks.get_mut(&backend_id).unwrap();
let utterance_id = UtteranceId::SpeechDispatcher(msg_id);
let utterance_id = UtteranceId::SpeechDispatcher(msg_id as u64);
if let Some(f) = cb.utterance_begin.as_mut() {
f(utterance_id);
}
@ -42,7 +42,7 @@ impl SpeechDispatcher {
let mut callbacks = CALLBACKS.lock().unwrap();
let backend_id = BackendId::SpeechDispatcher(client_id);
let cb = callbacks.get_mut(&backend_id).unwrap();
let utterance_id = UtteranceId::SpeechDispatcher(msg_id);
let utterance_id = UtteranceId::SpeechDispatcher(msg_id as u64);
if let Some(f) = cb.utterance_end.as_mut() {
f(utterance_id);
}
@ -53,7 +53,7 @@ impl SpeechDispatcher {
let mut callbacks = CALLBACKS.lock().unwrap();
let backend_id = BackendId::SpeechDispatcher(client_id);
let cb = callbacks.get_mut(&backend_id).unwrap();
let utterance_id = UtteranceId::SpeechDispatcher(msg_id);
let utterance_id = UtteranceId::SpeechDispatcher(msg_id as u64);
if let Some(f) = cb.utterance_stop.as_mut() {
f(utterance_id);
}
@ -188,11 +188,12 @@ impl Backend for SpeechDispatcher {
.0
.list_synthesis_voices()?
.iter()
.filter(|v| LanguageTag::parse(v.language.clone()).is_ok())
.map(|v| Voice {
id: v.name.clone(),
name: v.name.clone(),
gender: None,
language: LanguageIdentifier::from_str(&v.language).unwrap(),
language: LanguageTag::parse(v.language.clone()).unwrap(),
})
.collect::<Vec<Voice>>();
Ok(rv)

View File

@ -1,9 +1,9 @@
#[cfg(target_arch = "wasm32")]
use std::{str::FromStr, sync::Mutex};
use std::sync::Mutex;
use lazy_static::lazy_static;
use log::{info, trace};
use unic_langid::LanguageIdentifier;
use oxilangtag::LanguageTag;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::{
@ -248,7 +248,7 @@ impl Backend for Web {
return Ok(());
}
}
return Err(Error::OperationFailed);
Err(Error::OperationFailed)
} else {
Err(Error::NoneError)
}
@ -264,7 +264,7 @@ impl Drop for Web {
impl From<SpeechSynthesisVoice> for Voice {
fn from(other: SpeechSynthesisVoice) -> Self {
let language = LanguageIdentifier::from_str(&other.lang()).unwrap();
let language = LanguageTag::parse(other.lang()).unwrap();
Voice {
id: other.voice_uri(),
name: other.name(),

View File

@ -1,13 +1,12 @@
#[cfg(windows)]
use std::{
collections::{HashMap, VecDeque},
str::FromStr,
sync::Mutex,
};
use lazy_static::lazy_static;
use log::{info, trace};
use unic_langid::LanguageIdentifier;
use oxilangtag::LanguageTag;
use windows::{
Foundation::TypedEventHandler,
Media::{
@ -84,7 +83,7 @@ impl WinRt {
backend_to_speech_synthesizer.insert(bid, synth.clone());
drop(backend_to_speech_synthesizer);
let bid_clone = bid;
player.MediaEnded(TypedEventHandler::new(
player.MediaEnded(&TypedEventHandler::new(
move |sender: &Option<MediaPlayer>, _args| {
if let Some(sender) = sender {
let backend_to_media_player = BACKEND_TO_MEDIA_PLAYER.lock().unwrap();
@ -108,14 +107,14 @@ impl WinRt {
tts.Options()?.SetSpeakingRate(utterance.rate.into())?;
tts.Options()?.SetAudioPitch(utterance.pitch.into())?;
tts.Options()?.SetAudioVolume(utterance.volume.into())?;
tts.SetVoice(utterance.voice.clone())?;
let stream = tts
.SynthesizeTextToStreamAsync(utterance.text.as_str())?
.get()?;
tts.SetVoice(&utterance.voice)?;
let text = &utterance.text;
let stream =
tts.SynthesizeTextToStreamAsync(&text.into())?.get()?;
let content_type = stream.ContentType()?;
let source =
MediaSource::CreateFromStream(stream, content_type)?;
sender.SetSource(source)?;
MediaSource::CreateFromStream(&stream, &content_type)?;
sender.SetSource(&source)?;
sender.Play()?;
if let Some(callback) = callbacks.utterance_begin.as_mut() {
callback(utterance.id);
@ -193,10 +192,14 @@ impl Backend for WinRt {
self.synth.Options()?.SetSpeakingRate(self.rate.into())?;
self.synth.Options()?.SetAudioPitch(self.pitch.into())?;
self.synth.Options()?.SetAudioVolume(self.volume.into())?;
let stream = self.synth.SynthesizeTextToStreamAsync(text)?.get()?;
self.synth.SetVoice(&self.voice)?;
let stream = self
.synth
.SynthesizeTextToStreamAsync(&text.into())?
.get()?;
let content_type = stream.ContentType()?;
let source = MediaSource::CreateFromStream(stream, content_type)?;
self.player.SetSource(source)?;
let source = MediaSource::CreateFromStream(&stream, &content_type)?;
self.player.SetSource(&source)?;
self.player.Play()?;
let mut callbacks = CALLBACKS.lock().unwrap();
let callbacks = callbacks.get_mut(&self.id).unwrap();
@ -319,7 +322,7 @@ impl Backend for WinRt {
for v in SpeechSynthesizer::AllVoices()? {
let vid: String = v.Id()?.try_into()?;
if vid == voice.id {
self.voice = v.clone();
self.voice = v;
return Ok(());
}
}
@ -350,7 +353,7 @@ impl TryInto<Voice> for VoiceInformation {
Gender::Female
};
let language: String = self.Language()?.try_into()?;
let language = LanguageIdentifier::from_str(&language).unwrap();
let language = LanguageTag::parse(language).unwrap();
Ok(Voice {
id: self.Id()?.try_into()?,
name: self.DisplayName()?.try_into()?,

View File

@ -14,9 +14,10 @@ use std::collections::HashMap;
#[cfg(target_os = "macos")]
use std::ffi::CStr;
use std::fmt;
use std::rc::Rc;
#[cfg(windows)]
use std::string::FromUtf16Error;
use std::sync::{Arc, Mutex};
use std::sync::Mutex;
use std::{boxed::Box, sync::RwLock};
#[cfg(any(target_os = "macos", target_os = "ios"))]
@ -27,12 +28,12 @@ use lazy_static::lazy_static;
use libc::c_char;
#[cfg(target_os = "macos")]
use objc::{class, msg_send, sel, sel_impl};
pub use oxilangtag::LanguageTag;
#[cfg(target_os = "linux")]
use speech_dispatcher::Error as SpeechDispatcherError;
use thiserror::Error;
#[cfg(all(windows, feature = "tolk"))]
use tolk::Tolk;
pub use unic_langid::LanguageIdentifier;
mod backends;
@ -84,7 +85,7 @@ pub enum BackendId {
#[cfg(any(target_os = "macos", target_os = "ios"))]
AvFoundation(u64),
#[cfg(target_os = "linux")]
SpeechDispatcher(u64),
SpeechDispatcher(usize),
#[cfg(target_arch = "wasm32")]
Web(u64),
#[cfg(windows)]
@ -95,15 +96,15 @@ impl fmt::Display for BackendId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
#[cfg(target_os = "android")]
BackendId::Android(id) => writeln!(f, "{}", id),
BackendId::Android(id) => writeln!(f, "Android({id})"),
#[cfg(any(target_os = "macos", target_os = "ios"))]
BackendId::AvFoundation(id) => writeln!(f, "{}", id),
BackendId::AvFoundation(id) => writeln!(f, "AvFoundation({id})"),
#[cfg(target_os = "linux")]
BackendId::SpeechDispatcher(id) => writeln!(f, "{}", id),
BackendId::SpeechDispatcher(id) => writeln!(f, "SpeechDispatcher({id})"),
#[cfg(target_arch = "wasm32")]
BackendId::Web(id) => writeln!(f, "Web({})", id),
BackendId::Web(id) => writeln!(f, "Web({id})"),
#[cfg(windows)]
BackendId::WinRt(id) => writeln!(f, "{}", id),
BackendId::WinRt(id) => writeln!(f, "WinRT({id})"),
}
}
}
@ -143,13 +144,13 @@ impl fmt::Display for UtteranceId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self {
#[cfg(target_os = "android")]
UtteranceId::Android(id) => writeln!(f, "{}", id),
UtteranceId::Android(id) => writeln!(f, "Android({id})"),
#[cfg(target_os = "linux")]
UtteranceId::SpeechDispatcher(id) => writeln!(f, "{}", id),
UtteranceId::SpeechDispatcher(id) => writeln!(f, "SpeechDispatcher({id})"),
#[cfg(target_arch = "wasm32")]
UtteranceId::Web(id) => writeln!(f, "Web({})", id),
#[cfg(windows)]
UtteranceId::WinRt(id) => writeln!(f, "{}", id),
UtteranceId::WinRt(id) => writeln!(f, "WinRt({id})"),
}
}
}
@ -173,7 +174,7 @@ pub struct Features {
impl fmt::Display for Features {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
writeln!(f, "{:#?}", self)
writeln!(f, "{self:#?}")
}
}
@ -258,7 +259,7 @@ lazy_static! {
}
#[derive(Clone)]
pub struct Tts(Arc<RwLock<Box<dyn Backend>>>);
pub struct Tts(Rc<RwLock<Box<dyn Backend>>>);
unsafe impl Send for Tts {}
@ -271,18 +272,18 @@ impl Tts {
#[cfg(target_os = "linux")]
Backends::SpeechDispatcher => {
let tts = backends::SpeechDispatcher::new()?;
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
}
#[cfg(target_arch = "wasm32")]
Backends::Web => {
let tts = backends::Web::new()?;
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
}
#[cfg(all(windows, feature = "tolk"))]
Backends::Tolk => {
let tts = backends::Tolk::new();
if let Some(tts) = tts {
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
} else {
Err(Error::NoneError)
}
@ -290,20 +291,20 @@ impl Tts {
#[cfg(windows)]
Backends::WinRt => {
let tts = backends::WinRt::new()?;
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
}
#[cfg(target_os = "macos")]
Backends::AppKit => Ok(Tts(Arc::new(RwLock::new(Box::new(
backends::AppKit::new()?
))))),
Backends::AppKit => Ok(Tts(Rc::new(RwLock::new(
Box::new(backends::AppKit::new()?),
)))),
#[cfg(any(target_os = "macos", target_os = "ios"))]
Backends::AvFoundation => Ok(Tts(Arc::new(RwLock::new(Box::new(
Backends::AvFoundation => Ok(Tts(Rc::new(RwLock::new(Box::new(
backends::AvFoundation::new()?,
))))),
#[cfg(target_os = "android")]
Backends::Android => {
let tts = backends::Android::new()?;
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
}
};
if let Ok(backend) = backend {
@ -317,6 +318,7 @@ impl Tts {
}
}
#[allow(clippy::should_implement_trait)]
pub fn default() -> Result<Tts, Error> {
#[cfg(target_os = "linux")]
let tts = Tts::new(Backends::SpeechDispatcher);
@ -570,7 +572,7 @@ impl Tts {
if utterance_callbacks {
let mut callbacks = CALLBACKS.lock().unwrap();
let id = self.0.read().unwrap().id().unwrap();
let mut callbacks = callbacks.get_mut(&id).unwrap();
let callbacks = callbacks.get_mut(&id).unwrap();
callbacks.utterance_begin = callback;
Ok(())
} else {
@ -590,7 +592,7 @@ impl Tts {
if utterance_callbacks {
let mut callbacks = CALLBACKS.lock().unwrap();
let id = self.0.read().unwrap().id().unwrap();
let mut callbacks = callbacks.get_mut(&id).unwrap();
let callbacks = callbacks.get_mut(&id).unwrap();
callbacks.utterance_end = callback;
Ok(())
} else {
@ -610,7 +612,7 @@ impl Tts {
if utterance_callbacks {
let mut callbacks = CALLBACKS.lock().unwrap();
let id = self.0.read().unwrap().id().unwrap();
let mut callbacks = callbacks.get_mut(&id).unwrap();
let callbacks = callbacks.get_mut(&id).unwrap();
callbacks.utterance_stop = callback;
Ok(())
} else {
@ -639,7 +641,7 @@ impl Tts {
impl Drop for Tts {
fn drop(&mut self) {
if Arc::strong_count(&self.0) <= 1 {
if Rc::strong_count(&self.0) <= 1 {
if let Some(id) = self.0.read().unwrap().id() {
let mut callbacks = CALLBACKS.lock().unwrap();
callbacks.remove(&id);
@ -648,18 +650,18 @@ impl Drop for Tts {
}
}
#[derive(Clone, Copy, Debug)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Gender {
Male,
Female,
}
#[derive(Clone, Debug)]
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Voice {
pub(crate) id: String,
pub(crate) name: String,
pub(crate) gender: Option<Gender>,
pub(crate) language: LanguageIdentifier,
pub(crate) language: LanguageTag<String>,
}
impl Voice {
@ -675,7 +677,7 @@ impl Voice {
self.gender
}
pub fn language(&self) -> LanguageIdentifier {
pub fn language(&self) -> LanguageTag<String> {
self.language.clone()
}
}