Compare commits

...

11 Commits

11 changed files with 83 additions and 218 deletions

View File

@ -6,98 +6,16 @@ on:
- "v*" - "v*"
jobs: jobs:
check:
name: Check
strategy:
matrix:
os: [windows-latest, ubuntu-22.04, 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-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-rs/install@v0.1
with:
crate: cargo-make
- uses: actions-rs/cargo@v1
with:
command: make
args: build-web-example
publish: publish:
name: Publish name: Publish
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
needs: [check, check_web]
env: env:
CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }} CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v1
- uses: actions-rs/toolchain@v1
with:
target: wasm32-unknown-unknown
profile: minimal
toolchain: stable
override: true
- run: | - run: |
sudo apt-get update sudo apt-get update
sudo apt-get install -y libspeechd-dev sudo apt-get install -y libspeechd-dev
cargo login $CARGO_TOKEN cargo login $CARGO_TOKEN
cargo publish --no-default-features rustup toolchain install stable
cargo publish

View File

@ -12,106 +12,43 @@ jobs:
os: [windows-latest, ubuntu-22.04, macos-latest] os: [windows-latest, ubuntu-22.04, macos-latest]
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v1
- run: sudo apt-get update; sudo apt-get install -y libspeechd-dev - run: sudo apt-get update; sudo apt-get install -y libspeechd-dev
if: ${{ runner.os == 'Linux' }} if: ${{ runner.os == 'Linux' }}
- uses: actions-rs/toolchain@v1 - run: |
with: rustup toolchain install stable
profile: minimal cargo fmt --all --check
toolchain: stable cargo clippy --all-features
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: check_web:
name: Check Web name: Check Web
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v1 - run: |
- uses: actions-rs/toolchain@v1 rustup toolchain install stable
with: rustup target add wasm32-unknown-unknown
target: wasm32-unknown-unknown cargo fmt --all --check
profile: minimal cargo clippy --all-features --target wasm32-unknown-unknown
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
check_android: check_android:
name: Check Android name: Check Android
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v1 - run: |
- uses: actions-rs/toolchain@v1 rustup toolchain install stable
with: rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
profile: minimal cargo install -f cargo-apk
toolchain: stable cargo apk build
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
check_web_example: check_web_example:
name: Check Web Example name: Check Web Example
runs-on: ubuntu-22.04 runs-on: ubuntu-22.04
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v1 - run: |
- uses: actions-rs/toolchain@v1 rustup toolchain install stable
with: rustup target add wasm32-unknown-unknown
target: wasm32-unknown-unknown cargo install cargo-make
profile: minimal cargo make build-web-example
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

View File

@ -12,6 +12,7 @@ edition = "2021"
crate-type = ["lib", "cdylib", "staticlib"] crate-type = ["lib", "cdylib", "staticlib"]
[features] [features]
speech_dispatcher_0_9 = ["speech-dispatcher/0_9"]
speech_dispatcher_0_10 = ["speech-dispatcher/0_10"] speech_dispatcher_0_10 = ["speech-dispatcher/0_10"]
speech_dispatcher_0_11 = ["speech-dispatcher/0_11"] speech_dispatcher_0_11 = ["speech-dispatcher/0_11"]
default = ["speech_dispatcher_0_11"] default = ["speech_dispatcher_0_11"]
@ -32,7 +33,7 @@ tolk = { version = "0.5", optional = true }
windows = { version = "0.43", features = ["Foundation", "Foundation_Collections", "Media_Core", "Media_Playback", "Media_SpeechSynthesis", "Storage_Streams"] } windows = { version = "0.43", features = ["Foundation", "Foundation_Collections", "Media_Core", "Media_Playback", "Media_SpeechSynthesis", "Storage_Streams"] }
[target.'cfg(target_os = "linux")'.dependencies] [target.'cfg(target_os = "linux")'.dependencies]
speech-dispatcher = { version = "0.15", default-features = false } speech-dispatcher = { version = "0.16", default-features = false }
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
cocoa-foundation = "0.1" cocoa-foundation = "0.1"
@ -45,8 +46,10 @@ 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] [target.'cfg(target_os="android")'.dependencies]
jni = "0.19" jni = "0.20"
ndk-glue = "0.6" ndk-context = "0.1"
ndk-glue = "0.7"
[package.metadata.docs.rs] [package.metadata.docs.rs]
no-default-features = true no-default-features = true
features = ["speech_dispatcher_0_9"]

View File

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

View File

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-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"> <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" /> <meta-data android:name="android.app.lib_name" android:value="hello_world" />
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <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. // Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.3.72" buildscript {
repositories { repositories {
google() google()
jcenter() mavenCentral()
maven { maven {
url "https://plugins.gradle.org/m2/" 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" plugins {
classpath "gradle.plugin.com.github.willir.rust:plugin:0.3.4" id "com.android.application" version "7.3.0" apply false
// NOTE: Do not place your application dependencies here; they belong id "com.android.library" version "7.3.0" apply false
// in the individual module build.gradle files 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 { allprojects {
repositories { repositories {
google() google()
jcenter() mavenCentral()
} }
} }
task clean(type: Delete) { task clean(type: Delete) {
delete rootProject.buildDir delete rootProject.buildDir

View File

@ -10,5 +10,5 @@ edition = "2018"
crate-type = ["dylib"] crate-type = ["dylib"]
[dependencies] [dependencies]
ndk-glue = "0.6" ndk-glue = "0.7"
tts = { path = "../.." } tts = { path = "../.." }

View File

@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists 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

@ -179,8 +179,9 @@ impl Android {
let id = BackendId::Android(bid); let id = BackendId::Android(bid);
*backend_id += 1; *backend_id += 1;
drop(backend_id); drop(backend_id);
let native_activity = ndk_glue::native_activity(); let ctx = ndk_context::android_context();
let vm = Self::vm()?; let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }?;
let context = unsafe { JObject::from_raw(ctx.context().cast()) };
let env = vm.attach_current_thread_permanently()?; let env = vm.attach_current_thread_permanently()?;
let bridge = BRIDGE.lock().unwrap(); let bridge = BRIDGE.lock().unwrap();
if let Some(bridge) = &*bridge { if let Some(bridge) = &*bridge {
@ -188,7 +189,7 @@ impl Android {
let tts = env.new_object( let tts = env.new_object(
"android/speech/tts/TextToSpeech", "android/speech/tts/TextToSpeech",
"(Landroid/content/Context;Landroid/speech/tts/TextToSpeech$OnInitListener;)V", "(Landroid/content/Context;Landroid/speech/tts/TextToSpeech$OnInitListener;)V",
&[native_activity.activity().into(), bridge.into()], &[context.into(), bridge.into()],
)?; )?;
env.call_method( env.call_method(
tts, tts,
@ -229,9 +230,8 @@ impl Android {
} }
fn vm() -> Result<JavaVM, jni::errors::Error> { fn vm() -> Result<JavaVM, jni::errors::Error> {
let native_activity = ndk_glue::native_activity(); let ctx = ndk_context::android_context();
let vm_ptr = native_activity.vm(); unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) }
unsafe { jni::JavaVM::from_raw(vm_ptr) }
} }
} }

View File

@ -248,7 +248,7 @@ impl Backend for Web {
return Ok(()); return Ok(());
} }
} }
return Err(Error::OperationFailed); Err(Error::OperationFailed)
} else { } else {
Err(Error::NoneError) Err(Error::NoneError)
} }