Compare commits

...

69 Commits

Author SHA1 Message Date
35afabbdca Upgrade Gradle. 2023-04-26 09:55:33 -05:00
e331676855
Merge pull request #13 from retrohub-org/contribution_32-bits-ci
Add 32 bits builds in CI
2023-04-26 09:53:01 -05:00
c92135d452 Merge branch 'master' into pr/dylanjaide/7 2023-04-26 09:48:23 -05:00
Ricardo Subtil
1d963924ce Add 32 bits builds in CI 2023-03-18 15:43:44 +00:00
5abf6317ef Remove missing features. 2022-12-16 10:46:29 -06:00
d83b3689f5 Simplify screen reader detection code to use Tts APIs. 2022-12-16 10:24:32 -06:00
2dba6d0a55 Revert "Test on ubuntu-20.04 for older libc releases."
Ubuntu 20.04 doesn't appear to be supported by the Godot Rust bindings
due to only shipping glibc 2.31 when 2.32 is the minimum required
version.

This reverts commit 6d48c23e3e.
2022-12-12 08:18:06 -06:00
6d48c23e3e Test on ubuntu-20.04 for older libc releases. 2022-12-12 07:45:08 -06:00
f21d3357e9 Update dependencies from most recent work. 2022-12-07 09:39:52 -06:00
dba2d061ac Bump dependencies and upgrade to gdnative-rust 0.11. 2022-12-06 09:57:47 -06:00
Dylan Jaide White
bf2afec4b3 Best guess at Android implementation 2022-03-12 21:25:53 +00:00
Dylan Jaide White
2537d27886 Add Rust implementation of volume 2022-03-12 20:42:20 +00:00
Dylan Jaide White
8d95b3b5de Initial test of adding volume, javascript only for now 2022-03-12 18:04:53 +00:00
1c7686d09d Bump dependency. 2021-03-11 14:30:14 -06:00
b43b4fe19b Refactor to tolk feature. 2021-01-21 11:26:59 -06:00
5c1cf59d98 Bump dependency. 2021-01-18 11:10:43 -06:00
c8aabb02ad Bump dependencies. 2020-12-07 23:37:04 -06:00
58dfb757c4 Rustup is failing for some reason. 2020-12-03 15:07:14 -06:00
f800aebb14 Bump dependency. 2020-12-03 13:52:49 -06:00
890e32df80
Merge pull request #3 from metinc/patch-1
Add a short usage description.
2020-11-25 10:31:05 -06:00
d9d135d530 Bump dependency. 2020-11-25 10:25:14 -06:00
65311abdeb Remove unwrap in favor of expect. 2020-11-24 12:20:02 -06:00
Metin Celik
de6da09431
Add a short usage description. 2020-11-21 10:21:33 +01:00
691997023a Bump dependency version. 2020-11-18 08:40:21 -06:00
30b27c542e If removing quotes doesn't work, then I got nothing. 2020-11-17 22:07:55 -06:00
fbdc2a7724 I keep forgetting this is Powershell. 2020-11-17 21:56:19 -06:00
e8dfbb6a69 Escape and quote. 2020-11-17 20:22:01 -06:00
e2c1bfa7c9 Eliminate Clippy warnings. 2020-11-17 19:43:57 -06:00
b34c880a36 Switch to Rust GitHub actions. 2020-11-17 19:27:40 -06:00
e2c162c547 Cache Gradle artifacts in release builds. 2020-11-17 13:32:42 -06:00
413b68be63 Cache Gradle artifacts. 2020-11-17 13:24:58 -06:00
3ff48e2601 Quiet LLVM installation on release. 2020-11-17 13:17:17 -06:00
a0cc984fa1 Add caching for release builds. 2020-11-17 13:12:28 -06:00
ac0425b652 Set up environment variable for release. 2020-11-17 12:41:18 -06:00
140b80738b Introduce caching. 2020-11-17 12:39:51 -06:00
47782166d3 Tweak environment variable and try to install quietly. 2020-11-17 12:28:08 -06:00
55eea365c4 Not sure why we suddenly need this. 2020-11-17 12:10:21 -06:00
e21edf0c31 Bump dependency. 2020-11-17 10:54:15 -06:00
5529358651 Bump dependency. 2020-11-11 10:39:17 -06:00
3639e98f65 Bump dependency. 2020-11-03 12:15:24 -06:00
32c20ddf90 Bump tts-rs version. 2020-11-02 13:56:35 -06:00
760a7745f1 Bump dependency. 2020-11-02 11:38:34 -06:00
f759a67507 Upgrade env_logger. 2020-10-30 10:49:15 -05:00
7c25c6ad0e Bump crate version to fix WinRT bug. 2020-10-30 10:48:28 -05:00
d58bb881e5 Fix Android initialization. 2020-10-14 13:15:03 -05:00
0abf1ffcdd Update instructions for Godot 3.2.3 Android custom template changes. 2020-10-14 10:37:50 -05:00
893fae0c99 rm rm 2020-10-09 11:15:52 -05:00
93432f2a44 Fix broken setup of gdnlib file for release. 2020-10-09 10:23:01 -05:00
e483f3467b Add Utterance as tool script to work around https://github.com/godot-rust/godot-rust/issues/614. 2020-10-09 09:35:55 -05:00
8ed356fd47 Update .gitignore. 2020-10-09 07:16:58 -05:00
e19d154b99 Add support for separating Tolk dependency for use on UWP. 2020-10-08 20:44:05 -05:00
f7a2ac7760 Reference separate UWP DLL. 2020-10-08 20:31:56 -05:00
3c2e2220b0 Build separate UWP DLL. 2020-10-08 20:28:19 -05:00
17220b4634 Use cargo check and build with --all-features under Windows. 2020-10-08 20:18:45 -05:00
9243ea4e7f Implement utterance_stop signal on Android. 2020-10-08 11:10:16 -05:00
f105ee702b Statically link MSVC runtime on Windows. 2020-10-08 10:40:36 -05:00
1dabd5afd3 Implement stop signals. 2020-10-08 08:56:56 -05:00
2c73b45300 Bump tts dependency. 2020-10-08 08:46:38 -05:00
69b5c39f66 Eliminate Option in return. 2020-09-30 16:03:04 -05:00
ff247a3f19 Only set an utterance ID on the returned variant if we have one. 2020-09-30 15:25:59 -05:00
ed7f3920f6 Add signal support to Android. 2020-09-30 15:13:17 -05:00
41c4204224 Bump Android dependency to Godot 3.2.3. 2020-09-30 13:50:51 -05:00
c7563fa997 Pass utterance IDs into signals, and return an utterance ID when speaking. 2020-09-30 13:45:20 -05:00
68d1d9e011 WIP: Try passing in utterance to signals. 2020-09-30 11:57:50 -05:00
a71bf417b6 Bridge TTS callbacks to signals. 2020-09-29 11:41:00 -05:00
0c9efa5c7b Minor convention cleanup. 2020-09-29 10:56:32 -05:00
abe9ab3f55 Add property indicating whether utterance callbacks are supported. 2020-09-29 10:53:35 -05:00
795cc4790c Add utterance_begin and utterance_end signals.
Unfortunately, I can't figure out how to pass the utterance ID to these signals because I don't see that the GDNative Rust bindings support objects of one type creating objects of another (I.e. nodes creating references.) If I'm wrong, PRs or suggestions welcome.
2020-09-29 10:44:52 -05:00
cb7eda45e2 Pin minimum tts version to work around Tolk string-handling issue. 2020-09-21 15:19:36 -05:00
17 changed files with 868 additions and 383 deletions

2
.cargo/config Normal file
View File

@ -0,0 +1,2 @@
[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]

View File

@ -2,51 +2,42 @@ name: Build
on: on:
push: push:
branches: [master]
pull_request: pull_request:
branches: [master]
jobs: jobs:
build_linux: check:
name: Build Linux name: Check
runs-on: ubuntu-latest strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps: steps:
- uses: actions/checkout@v2 - 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' }}
- run: | - run: |
sudo apt-get update choco install -qy llvm
sudo apt-get install -y libspeechd-dev echo LIBCLANG_PATH=c:\program` files\llvm\bin >> $Env:GITHUB_ENV
rustup update if: ${{ runner.os == 'Windows' }}
cargo build --release - uses: actions-rs/toolchain@v1
with:
build_windows: profile: minimal
name: Build Windows toolchain: stable
runs-on: windows-latest components: rustfmt, clippy
steps: override: true
- uses: actions/checkout@v2 - uses: actions-rs/cargo@v1
- run: | with:
choco install -y llvm command: check
rustup update args: --all-features --examples
cargo build --release - uses: actions-rs/cargo@v1
with:
build_macos: command: fmt
name: Build MacOS args: --all -- --check
runs-on: macos-latest - uses: actions-rs/clippy-check@v1
steps: with:
- uses: actions/checkout@v2 token: ${{ secrets.GITHUB_TOKEN }}
- run: | args: --all-features
rustup update
cargo build --release
build_ios:
name: Build iOS
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- run: |
rustup update
rustup target add aarch64-apple-ios x86_64-apple-ios
cargo install cargo-lipo
cargo lipo --release
build_android: build_android:
name: Build Android name: Build Android
@ -55,5 +46,10 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with: with:
lfs: true lfs: true
- uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- run: | - run: |
./gradlew assemble ./gradlew assemble

View File

@ -11,41 +11,102 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- run: | - run: |
sudo apt-get update sudo apt-get update
sudo apt-get install -y libspeechd-dev sudo apt-get install -y libspeechd-dev
rustup update
cargo build --release cargo build --release
mv target linux mkdir linux
mv target/release/*.so linux
- uses: actions/upload-artifact@v1 - uses: actions/upload-artifact@v1
with: with:
name: linux name: linux
path: linux path: linux
build_linux_32:
name: Build Linux (32 bits)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- run: |
sudo dpkg --add-architecture i386
sudo apt-get update
sudo apt-get install -y libspeechd-dev:i386 gcc-multilib
rustup target add i686-unknown-linux-gnu
cargo build --release --target i686-unknown-linux-gnu
mkdir linux-32
mv target/i686-unknown-linux-gnu/release/*.so linux-32
- uses: actions/upload-artifact@v1
with:
name: linux-32
path: linux-32
build_windows: build_windows:
name: Build Windows name: Build Windows
runs-on: windows-latest runs-on: windows-latest
env:
LIBCLANG_PATH: c:\program files\llvm\bin
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- run: | - run: |
choco install -y llvm choco install -qy llvm
rustup update
cargo build --release cargo build --release
move target windows mkdir windows
move target\release\*.dll windows
- uses: actions/upload-artifact@v1 - uses: actions/upload-artifact@v1
with: with:
name: windows name: windows
path: windows path: windows
build_windows_32:
name: Build Windows (32 bits)
runs-on: windows-latest
env:
LIBCLANG_PATH: c:\program files\llvm\bin
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- run: |
choco install -qy llvm
rustup target add i686-pc-windows-msvc
cargo build --release --target i686-pc-windows-msvc
mkdir windows-32
move target\i686-pc-windows-msvc\release\*.dll windows-32
- uses: actions/upload-artifact@v1
with:
name: windows-32
path: windows-32
build_uwp:
name: Build UWP
runs-on: windows-latest
env:
LIBCLANG_PATH: c:\program files\llvm\bin
steps:
- uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- run: |
choco install -y llvm
cargo build --release
mkdir uwp
move target\release\godot_tts.dll uwp\godot_tts.uwp.dll
- uses: actions/upload-artifact@v1
with:
name: uwp
path: uwp
build_macos: build_macos:
name: Build MacOS name: Build MacOS
runs-on: macos-latest runs-on: macos-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- run: | - run: |
rustup update
cargo build --release cargo build --release
mv target macos mkdir macos
mv target/release/*.dylib macos
- uses: actions/upload-artifact@v1 - uses: actions/upload-artifact@v1
with: with:
name: macos name: macos
@ -58,6 +119,11 @@ jobs:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with: with:
lfs: true lfs: true
- uses: actions/cache@v2
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- run: | - run: |
./gradlew assemble ./gradlew assemble
mv build android mv build android
@ -71,12 +137,13 @@ jobs:
runs-on: macos-latest runs-on: macos-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: Swatinem/rust-cache@v1
- run: | - run: |
rustup update
rustup target add aarch64-apple-ios x86_64-apple-ios rustup target add aarch64-apple-ios x86_64-apple-ios
cargo install cargo-lipo cargo install cargo-lipo
cargo lipo --release cargo lipo --release
mv target ios mkdir ios
mv target/universal/release/*.a ios
- uses: actions/upload-artifact@v1 - uses: actions/upload-artifact@v1
with: with:
name: ios name: ios
@ -85,15 +152,34 @@ jobs:
package: package:
name: Package name: Package
runs-on: ubuntu-latest runs-on: ubuntu-latest
needs: [build_linux, build_windows, build_macos, build_android, build_ios] needs:
[
build_linux,
build_linux_32,
build_windows,
build_windows_32,
build_uwp,
build_macos,
build_android,
build_ios,
]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- uses: actions/download-artifact@v1 - uses: actions/download-artifact@v1
with: with:
name: linux name: linux
- uses: actions/download-artifact@v1
with:
name: linux-32
- uses: actions/download-artifact@v1 - uses: actions/download-artifact@v1
with: with:
name: windows name: windows
- uses: actions/download-artifact@v1
with:
name: windows-32
- uses: actions/download-artifact@v1
with:
name: uwp
- uses: actions/download-artifact@v1 - uses: actions/download-artifact@v1
with: with:
name: macos name: macos
@ -104,20 +190,20 @@ jobs:
with: with:
name: ios name: ios
- run: | - run: |
mkdir godot-tts mkdir -p godot-tts/target/release/32
cp godot-tts.gdnlib.release godot-tts/godot-tts.gdnlib cp linux/*.so godot-tts/target/release
cp godot-tts.gdap godot-tts/ cp linux-32/*.so godot-tts/target/release/32
mkdir -p godot-tts/target/release cp windows/*.dll godot-tts/target/release
cp linux/release/*.so godot-tts/target/release cp windows-32/*.dll godot-tts/target/release/32
cp windows/release/*.dll godot-tts/target/release cp uwp/*.dll godot-tts/target/release
cp macos/release/*.dylib godot-tts/target/release cp macos/*.dylib godot-tts/target/release
cp android/outputs/aar/godot-tts.aar godot-tts/ cp android/outputs/aar/godot-tts.aar godot-tts/
cp ios/universal/release/*.a godot-tts/target/release cp ios/*.a godot-tts/target/release
cp LICENSE godot-tts cp LICENSE godot-tts
cp README.md godot-tts cp README.md godot-tts
cp TTS.gd godot-tts.g* godot-tts cp TTS.gd godot-tts.g* godot-tts
cp godot-tts.gdnlib.release godot-tts/godot-tts.gdnlib rm godot-tts/*.gdnlib
rm godot-tts/*.release mv godot-tts/godot-tts.gdnlib.release godot-tts/godot-tts.gdnlib
zip -r9 godot-tts godot-tts zip -r9 godot-tts godot-tts
- uses: actions/create-release@v1 - uses: actions/create-release@v1
id: create_release id: create_release

3
.gitignore vendored
View File

@ -7,3 +7,6 @@ bazel-out
bazel-testlogs bazel-testlogs
build build
.gradle .gradle
.classpath
.project
.settings

View File

@ -8,9 +8,6 @@ edition = "2018"
crate-type = ["staticlib", "cdylib"] crate-type = ["staticlib", "cdylib"]
[dependencies] [dependencies]
env_logger = "0.7" env_logger = "0.10"
gdnative = "0.9.0-preview.0" gdnative = "0.11"
tts = "0.6" tts = { version = "0.25", features = ["tolk"] }
[target.'cfg(windows)'.dependencies]
tolk = "0.2"

View File

@ -7,7 +7,7 @@ This addon was primarily developed for the [Godot Accessibility addon](https://g
Text-to-speech is complicated, and some features may not work everywhere. Most optional features have an associated boolean property used to determine if the feature is available. Further, while I do attempt to ensure that this addon works as well as possible on all platforms, there may be bugs, and pull requests are welcome. Known supported platforms include: Text-to-speech is complicated, and some features may not work everywhere. Most optional features have an associated boolean property used to determine if the feature is available. Further, while I do attempt to ensure that this addon works as well as possible on all platforms, there may be bugs, and pull requests are welcome. Known supported platforms include:
* Windows * Windows
* Screen readers/SAPI via Tolk * Screen readers/SAPI via Tolk (requires `use_tolk` Cargo feature)
* WinRT * WinRT
* Linux via [Speech Dispatcher](https://freebsoft.org/speechd) * Linux via [Speech Dispatcher](https://freebsoft.org/speechd)
* MacOS * MacOS
@ -33,21 +33,30 @@ The public-facing API is contained entirely within [TTS.GD](https://github.com/l
Download the [latest release](https://github.com/lightsoutgames/godot-tts/releases). Download the [latest release](https://github.com/lightsoutgames/godot-tts/releases).
## Usage
Inside your projects root folder create a new folder named _addons_. Then extract _godot-tts.zip_ into that folder. After attaching TTS.GD to a node you can make calls to the API.
## Notes on Android ## Notes on Android
Usage on Android is a bit more complicated: Usage on Android is a bit more complicated:
* Set up a [custom Android build](https://docs.godotengine.org/en/latest/getting_started/workflow/export/android_custom_build.html). * Set up a [custom Android build](https://docs.godotengine.org/en/latest/getting_started/workflow/export/android_custom_build.html).
* Create a directory reachable at _res://android/plugins_ and place the _godot-tts.aar_ and _.godot-tts.gdap_ files from a release into that directory. * Create a directory reachable at _res://android/plugins_ and place the _godot-tts.aar_ and _.godot-tts.gdap_ files from a release into that directory.
* Update _res://android/build/build.gradle_ to specify a `minSdkVersion` of at least 21: * Update _res://android/build/config.gradle_ to specify a `minSdk` of at least 21. Individual versions may vary, but `minSdk` is the critical value from this example:
``` ```
defaultConfig { ext.versions = [
minSdkVersion 21 androidGradlePlugin: '3.5.3',
targetSdkVersion 29 compileSdk : 29,
versionCode pluginVersionCode minSdk : 21,
versionName pluginVersionName targetSdk : 29,
} buildTools : '29.0.3',
supportCoreUtils : '1.0.0',
kotlinVersion : '1.3.61',
v4Support : '1.0.0'
]
``` ```
## Notes on Universal Windows Platform ## Notes on Universal Windows Platform

131
TTS.gd
View File

@ -1,11 +1,16 @@
tool tool
extends Node extends Node
signal utterance_begin(utterance)
signal utterance_end(utterance)
signal utterance_stop(utterance)
var TTS var TTS
var tts var tts
signal done
func _init(): func _init():
if OS.get_name() == "Server" or OS.has_feature("JavaScript"): if OS.get_name() == "Server" or OS.has_feature("JavaScript"):
@ -16,14 +21,86 @@ func _init():
TTS = preload("godot-tts.gdns") TTS = preload("godot-tts.gdns")
if TTS and (TTS.can_instance() or Engine.editor_hint): if TTS and (TTS.can_instance() or Engine.editor_hint):
tts = TTS.new() tts = TTS.new()
if tts:
if not tts is JNISingleton:
self.add_child(tts)
if self.are_utterance_callbacks_supported:
tts.connect("utterance_begin", self, "_on_utterance_begin")
tts.connect("utterance_end", self, "_on_utterance_end")
tts.connect("utterance_stop", self, "_on_utterance_stop")
else: else:
print_debug("TTS not available!") print_debug("TTS not available!")
func _ready(): func _ready():
pause_mode = Node.PAUSE_MODE_PROCESS pause_mode = Node.PAUSE_MODE_PROCESS
func _get_min_volume():
if OS.has_feature('JavaScript'):
return 0
else:
return 0
var min_volume setget , _get_min_volume
func _get_max_volume():
if OS.has_feature('JavaScript'):
return 1.0
else:
return 0
var max_volume setget , _get_max_volume
func _get_normal_volume():
if OS.has_feature('JavaScript'):
return 1.0
else:
return 0
var normal_volume setget , _get_normal_volume
var javascript_volume = self.normal_volume
func _set_volume(volume):
if volume < self.min_volume:
volume = self.min_volume
elif volume > self.max_volume:
volume = self.max_volume
if OS.has_feature('JavaScript'):
javascript_volume = volume
func _get_volume():
if OS.has_feature('JavaScript'):
return javascript_volume
else:
return 0
var volume setget _set_volume, _get_volume
func _get_volume_percentage():
return range_lerp(self.volume, self.min_volume, self.max_volume, 0, 100)
func _set_volume_percentage(v):
self.rate = range_lerp(v, 0, 100, self.min_volume, self.max_volume)
var volume_percentage setget _set_volume_percentage, _get_volume_percentage
func _get_normal_volume_percentage():
return range_lerp(self.normal_volume, self.min_volume, self.max_volume, 0, 100)
var normal_volume_percentage setget , _get_normal_volume_percentage
func _get_min_rate(): func _get_min_rate():
if OS.has_feature('JavaScript'): if OS.has_feature('JavaScript'):
return 0.1 return 0.1
@ -114,24 +191,27 @@ var normal_rate_percentage setget , _get_rate_percentage
func speak(text, interrupt := true): func speak(text, interrupt := true):
var utterance
if tts != null: if tts != null:
tts.speak(text, interrupt) utterance = tts.speak(text, interrupt)
elif OS.has_feature('JavaScript'): elif OS.has_feature('JavaScript'):
var code = ( var code = (
""" """
let utterance = new SpeechSynthesisUtterance("%s") let utterance = new SpeechSynthesisUtterance("%s")
utterance.rate = %s utterance.rate = %s
""" utterance.volume = %s
% [text.replace("\n", " "), javascript_rate] """
% [text.replace("\n", " "), javascript_rate, javascript_volume]
) )
if interrupt: if interrupt:
code += """ code += """
window.speechSynthesis.cancel() window.speechSynthesis.cancel()
""" """
code += "window.speechSynthesis.speak(utterance)" code += "window.speechSynthesis.speak(utterance)"
JavaScript.eval(code) JavaScript.eval(code)
else: else:
print_debug("%s: %s" % [text, interrupt]) print_debug("%s: %s" % [text, interrupt])
return utterance
func stop(): func stop():
@ -141,7 +221,7 @@ func stop():
JavaScript.eval("window.speechSynthesis.cancel()") JavaScript.eval("window.speechSynthesis.cancel()")
func get_is_rate_supported(): func _get_is_rate_supported():
if Engine.has_singleton("GodotTTS"): if Engine.has_singleton("GodotTTS"):
return true return true
elif OS.has_feature('JavaScript'): elif OS.has_feature('JavaScript'):
@ -152,7 +232,21 @@ func get_is_rate_supported():
return false return false
var is_rate_supported setget , get_is_rate_supported var is_rate_supported setget , _get_is_rate_supported
func _get_are_utterance_callbacks_supported():
if Engine.has_singleton("GodotTTS"):
return true
elif OS.has_feature('JavaScript'):
return false
elif tts != null:
return tts.are_utterance_callbacks_supported()
else:
return false
var are_utterance_callbacks_supported setget , _get_are_utterance_callbacks_supported
func _get_can_detect_is_speaking(): func _get_can_detect_is_speaking():
@ -214,15 +308,16 @@ func singular_or_plural(count, singular, plural):
return plural return plural
var _was_speaking = false func _on_utterance_begin(utterance):
emit_signal("utterance_begin", utterance)
func _process(delta): func _on_utterance_end(utterance):
if self.is_speaking: emit_signal("utterance_end", utterance)
_was_speaking = true
elif _was_speaking:
emit_signal("done") func _on_utterance_stop(utterance):
_was_speaking = false emit_signal("utterance_stop", utterance)
func _exit_tree(): func _exit_tree():

View File

@ -2,14 +2,17 @@
Server.64="res://addons/godot-tts/target/debug/libgodot_tts.so" Server.64="res://addons/godot-tts/target/debug/libgodot_tts.so"
Windows.64="res://addons/godot-tts/target/debug/godot_tts.dll" Windows.64="res://addons/godot-tts/target/debug/godot_tts.dll"
Windows.32="res://addons/godot-tts/target/debug/32/godot_tts.dll"
UWP.64="res://addons/godot-tts/target/debug/godot_tts.dll" UWP.64="res://addons/godot-tts/target/debug/godot_tts.dll"
X11.64="res://addons/godot-tts/target/debug/libgodot_tts.so" X11.64="res://addons/godot-tts/target/debug/libgodot_tts.so"
X11.32="res://addons/godot-tts/target/debug/32/libgodot_tts.so"
OSX.64="res://addons/godot-tts/target/debug/libgodot_tts.dylib" OSX.64="res://addons/godot-tts/target/debug/libgodot_tts.dylib"
IOS="res://addons/godot-tts/target/universal/debug/libgodot_tts.a" IOS="res://addons/godot-tts/target/debug/libgodot_tts.a"
[dependencies] [dependencies]
Windows.64=["res://addons/godot-tts/target/debug/nvdaControllerClient64.dll", "res://addons/godot-tts/target/debug/SAAPI64.dll"] Windows.64=[ "res://addons/godot-tts/target/debug/nvdaControllerClient64.dll", "res://addons/godot-tts/target/debug/SAAPI64.dll" ]
Windows.32=[ "res://addons/godot-tts/target/debug/32/dolapi32.dll", "res://addons/godot-tts/target/debug/32/nvdaControllerClient32.dll", "res://addons/godot-tts/target/debug/32/SAAPI32.dll" ]
[general] [general]

View File

@ -2,15 +2,17 @@
Server.64="res://addons/godot-tts/target/release/libgodot_tts.so" Server.64="res://addons/godot-tts/target/release/libgodot_tts.so"
Windows.64="res://addons/godot-tts/target/release/godot_tts.dll" Windows.64="res://addons/godot-tts/target/release/godot_tts.dll"
UWP.64="res://addons/godot-tts/target/release/godot_tts.dll" Windows.32="res://addons/godot-tts/target/release/32/godot_tts.dll"
UWP.64="res://addons/godot-tts/target/release/godot_tts.uwp.dll"
X11.64="res://addons/godot-tts/target/release/libgodot_tts.so" X11.64="res://addons/godot-tts/target/release/libgodot_tts.so"
X11.32="res://addons/godot-tts/target/release/32/libgodot_tts.so"
OSX.64="res://addons/godot-tts/target/release/libgodot_tts.dylib" OSX.64="res://addons/godot-tts/target/release/libgodot_tts.dylib"
IOS="res://addons/godot-tts/target/release/libgodot_tts.a" IOS="res://addons/godot-tts/target/release/libgodot_tts.a"
[dependencies] [dependencies]
Windows.64=["res://addons/godot-tts/target/release/nvdaControllerClient64.dll", "res://addons/godot-tts/target/release/SAAPI64.dll"] Windows.64=[ "res://addons/godot-tts/target/release/nvdaControllerClient64.dll", "res://addons/godot-tts/target/release/SAAPI64.dll" ]
X11.64=[ ] Windows.32=[ "res://addons/godot-tts/target/release/32/dolapi32.dll", "res://addons/godot-tts/target/release/32/nvdaControllerClient32.dll", "res://addons/godot-tts/target/release/32/SAAPI32.dll" ]
[general] [general]

Binary file not shown.

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

286
gradlew vendored
View File

@ -1,78 +1,129 @@
#!/usr/bin/env sh #!/bin/sh
#
# Copyright © 2015-2021 the original authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
############################################################################## ##############################################################################
## #
## Gradle start up script for UN*X # Gradle start up script for POSIX generated by Gradle.
## #
# Important for running:
#
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
# noncompliant, but you have some other compliant shell such as ksh or
# bash, then to run this script, type that shell name before the whole
# command line, like:
#
# ksh Gradle
#
# Busybox and similar reduced shells will NOT work, because this script
# requires all of these POSIX shell features:
# * functions;
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
# * compound commands having a testable exit status, especially «case»;
# * various built-in commands including «command», «set», and «ulimit».
#
# Important for patching:
#
# (2) This script targets any POSIX shell, so it avoids extensions provided
# by Bash, Ksh, etc; in particular arrays are avoided.
#
# The "traditional" practice of packing multiple parameters into a
# space-separated string is a well documented source of bugs and security
# problems, so this is (mostly) avoided, by progressively accumulating
# options in "$@", and eventually passing that to Java.
#
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
# see the in-line comments for details.
#
# There are tweaks for specific operating systems such as AIX, CygWin,
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
#
############################################################################## ##############################################################################
# Attempt to set APP_HOME # Attempt to set APP_HOME
# Resolve links: $0 may be a link # Resolve links: $0 may be a link
PRG="$0" app_path=$0
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do # Need this for daisy-chained symlinks.
ls=`ls -ld "$PRG"` while
link=`expr "$ls" : '.*-> \(.*\)$'` APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
if expr "$link" : '/.*' > /dev/null; then [ -h "$app_path" ]
PRG="$link" do
else ls=$( ls -ld "$app_path" )
PRG=`dirname "$PRG"`"/$link" link=${ls#*' -> '}
fi case $link in #(
/*) app_path=$link ;; #(
*) app_path=$APP_HOME$link ;;
esac
done done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle" APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"` APP_BASE_NAME=${0##*/}
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m"' DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value. # Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum" MAX_FD=maximum
warn () { warn () {
echo "$*" echo "$*"
} } >&2
die () { die () {
echo echo
echo "$*" echo "$*"
echo echo
exit 1 exit 1
} } >&2
# OS specific support (must be 'true' or 'false'). # OS specific support (must be 'true' or 'false').
cygwin=false cygwin=false
msys=false msys=false
darwin=false darwin=false
nonstop=false nonstop=false
case "`uname`" in case "$( uname )" in #(
CYGWIN* ) CYGWIN* ) cygwin=true ;; #(
cygwin=true Darwin* ) darwin=true ;; #(
;; MSYS* | MINGW* ) msys=true ;; #(
Darwin* ) NONSTOP* ) nonstop=true ;;
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM. # Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables # IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java" JAVACMD=$JAVA_HOME/jre/sh/java
else else
JAVACMD="$JAVA_HOME/bin/java" JAVACMD=$JAVA_HOME/bin/java
fi fi
if [ ! -x "$JAVACMD" ] ; then if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
@ -81,7 +132,7 @@ Please set the JAVA_HOME variable in your environment to match the
location of your Java installation." location of your Java installation."
fi fi
else else
JAVACMD="java" JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the Please set the JAVA_HOME variable in your environment to match the
@ -89,84 +140,95 @@ location of your Java installation."
fi fi
# Increase the maximum file descriptors if we can. # Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
MAX_FD_LIMIT=`ulimit -H -n` case $MAX_FD in #(
if [ $? -eq 0 ] ; then max*)
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD=$( ulimit -H -n ) ||
MAX_FD="$MAX_FD_LIMIT" warn "Could not query maximum file descriptor limit"
fi esac
ulimit -n $MAX_FD case $MAX_FD in #(
if [ $? -ne 0 ] ; then '' | soft) :;; #(
warn "Could not set maximum file descriptor limit: $MAX_FD" *)
fi ulimit -n "$MAX_FD" ||
else warn "Could not set maximum file descriptor limit to $MAX_FD"
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin, switch paths to Windows format before running java
if $cygwin ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=$((i+1))
done
case $i in
(0) set -- ;;
(1) set -- "$args0" ;;
(2) set -- "$args0" "$args1" ;;
(3) set -- "$args0" "$args1" "$args2" ;;
(4) set -- "$args0" "$args1" "$args2" "$args3" ;;
(5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
(6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
(7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
(8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
(9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac esac
fi fi
# Escape application args # Collect all arguments for the java command, stacking in reverse order:
save () { # * args from the command line
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done # * the main class name
echo " " # * -classpath
} # * -D...appname settings
APP_ARGS=$(save "$@") # * --module-path (only if needed)
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
# Collect all arguments for the java command, following the shell quoting and substitution rules # For Cygwin or MSYS, switch paths to Windows format before running java
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" if "$cygwin" || "$msys" ; then
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong JAVACMD=$( cygpath --unix "$JAVACMD" )
if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
cd "$(dirname "$0")" # Now convert the arguments - kludge to limit ourselves to /bin/sh
for arg do
if
case $arg in #(
-*) false ;; # don't mess with options #(
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
[ -e "$t" ] ;; #(
*) false ;;
esac
then
arg=$( cygpath --path --ignore --mixed "$arg" )
fi
# Roll the args list around exactly as many times as the number of
# args, so each arg winds up back in the position where it started, but
# possibly modified.
#
# NB: a `for` loop captures its iteration list before it begins, so
# changing the positional parameters here affects neither the number of
# iterations, nor the values presented in `arg`.
shift # remove old arg
set -- "$@" "$arg" # push replacement arg
done
fi fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
-classpath "$CLASSPATH" \
org.gradle.wrapper.GradleWrapperMain \
"$@"
# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
#
# In Bash we could simply go:
#
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
# set -- "${ARGS[@]}" "$@"
#
# but POSIX shell has neither arrays nor command substitution, so instead we
# post-process each arg (as a line of input to sed) to backslash-escape any
# character that might be a shell metacharacter, then use eval to reverse
# that process (while maintaining the separation between arguments), and wrap
# the whole thing up as a single "set" statement.
#
# This will of course break if any of these variables contains a newline or
# an unmatched quote.
#
eval "set -- $(
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
xargs -n1 |
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
tr '\n' ' '
)" '"$@"'
exec "$JAVACMD" "$@" exec "$JAVACMD" "$@"

43
gradlew.bat vendored
View File

@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem https://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@if "%DEBUG%" == "" @echo off @if "%DEBUG%" == "" @echo off
@rem ########################################################################## @rem ##########################################################################
@rem @rem
@ -13,15 +29,18 @@ if "%DIRNAME%" == "" set DIRNAME=.
set APP_BASE_NAME=%~n0 set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME% set APP_HOME=%DIRNAME%
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
set DEFAULT_JVM_OPTS="-Xmx64m" set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
@rem Find java.exe @rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome if defined JAVA_HOME goto findJavaFromJavaHome
set JAVA_EXE=java.exe set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1 %JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto init if "%ERRORLEVEL%" == "0" goto execute
echo. echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
@ -35,7 +54,7 @@ goto fail
set JAVA_HOME=%JAVA_HOME:"=% set JAVA_HOME=%JAVA_HOME:"=%
set JAVA_EXE=%JAVA_HOME%/bin/java.exe set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto init if exist "%JAVA_EXE%" goto execute
echo. echo.
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
@ -45,28 +64,14 @@ echo location of your Java installation.
goto fail goto fail
:init
@rem Get command-line arguments, handling Windows variants
if not "%OS%" == "Windows_NT" goto win9xME_args
:win9xME_args
@rem Slurp the command line arguments.
set CMD_LINE_ARGS=
set _SKIP=2
:win9xME_args_slurp
if "x%~1" == "x" goto execute
set CMD_LINE_ARGS=%*
:execute :execute
@rem Setup the command line @rem Setup the command line
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
:end :end
@rem End local scope for the variables with windows NT shell @rem End local scope for the variables with windows NT shell

BIN
libs/godot-lib.3.2.2.stable.release.aar (Stored with Git LFS)

Binary file not shown.

BIN
libs/godot-lib.3.2.3.stable.release.aar (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -1,21 +1,132 @@
use std::sync::mpsc::{channel, Receiver};
use gdnative::prelude::*; use gdnative::prelude::*;
use tts::{Features, TTS as Tts}; use tts::{Features, Tts, UtteranceId};
#[derive(NativeClass)]
struct Utterance(pub(crate) Option<UtteranceId>);
#[methods]
impl Utterance {
fn new(_owner: &Reference) -> Self {
Self(None)
}
}
#[allow(clippy::enum_variant_names)]
enum Msg {
UtteranceBegin(UtteranceId),
UtteranceEnd(UtteranceId),
UtteranceStop(UtteranceId),
}
#[allow(clippy::upper_case_acronyms)]
#[derive(NativeClass)] #[derive(NativeClass)]
#[inherit(Node)] #[inherit(Node)]
#[register_with(Self::register_properties)] #[register_with(Self::register)]
struct TTS(Tts); struct TTS(Tts, Receiver<Msg>);
#[methods] #[methods]
impl TTS { impl TTS {
fn new(_owner: &Node) -> Self { fn new(owner: &Node) -> Self {
let tts = Tts::default().unwrap(); owner.set_pause_mode(2);
Self(tts) let tts = Tts::default().expect("Failed to initialize TTS");
let (tx, rx) = channel();
let Features {
utterance_callbacks,
..
} = tts.supported_features();
if utterance_callbacks {
let tx_end = tx.clone();
let tx_stop = tx.clone();
tts.on_utterance_begin(Some(Box::new(move |utterance| {
tx.send(Msg::UtteranceBegin(utterance))
.expect("Failed to send UtteranceBegin");
})))
.expect("Failed to set utterance_begin callback");
tts.on_utterance_end(Some(Box::new(move |utterance| {
tx_end
.send(Msg::UtteranceEnd(utterance))
.expect("Failed to send UtteranceEnd");
})))
.expect("Failed to set utterance_end callback");
tts.on_utterance_stop(Some(Box::new(move |utterance| {
tx_stop
.send(Msg::UtteranceStop(utterance))
.expect("Failed to send UtteranceStop");
})))
.expect("Failed to set utterance_stop callback");
}
Self(tts, rx)
} }
fn register_properties(builder: &ClassBuilder<Self>) { fn register(builder: &ClassBuilder<Self>) {
builder builder
.add_property("rate") .property("volume")
.with_getter(|this: &TTS, _| match this.0.get_volume() {
Ok(volume) => volume,
_ => 0.,
})
.with_setter(|this: &mut TTS, _, v: f32| {
let Features {
volume: volume_supported,
..
} = this.0.supported_features();
if volume_supported {
let mut v = v;
if v < this.0.min_volume() {
v = this.0.min_volume();
} else if v > this.0.max_volume() {
v = this.0.max_volume();
}
this.0.set_volume(v).expect("Failed to set volume");
}
})
.done();
builder
.property("min_volume")
.with_getter(|this: &TTS, _| {
let Features {
volume: volume_supported,
..
} = this.0.supported_features();
if volume_supported {
this.0.min_volume()
} else {
0.
}
})
.done();
builder
.property("max_volume")
.with_getter(|this: &TTS, _| {
let Features {
volume: volume_supported,
..
} = this.0.supported_features();
if volume_supported {
this.0.max_volume()
} else {
0.
}
})
.done();
builder
.property("normal_volume")
.with_getter(|this: &TTS, _| {
let Features {
volume: volume_supported,
..
} = this.0.supported_features();
if volume_supported {
this.0.normal_volume()
} else {
0.
}
})
.done();
builder
.property("rate")
.with_getter(|this: &TTS, _| match this.0.get_rate() { .with_getter(|this: &TTS, _| match this.0.get_rate() {
Ok(rate) => rate, Ok(rate) => rate,
_ => 0., _ => 0.,
@ -32,12 +143,12 @@ impl TTS {
} else if v > this.0.max_rate() { } else if v > this.0.max_rate() {
v = this.0.max_rate(); v = this.0.max_rate();
} }
this.0.set_rate(v).unwrap(); this.0.set_rate(v).expect("Failed to set rate");
} }
}) })
.done(); .done();
builder builder
.add_property("min_rate") .property("min_rate")
.with_getter(|this: &TTS, _| { .with_getter(|this: &TTS, _| {
let Features { let Features {
rate: rate_supported, rate: rate_supported,
@ -51,7 +162,7 @@ impl TTS {
}) })
.done(); .done();
builder builder
.add_property("max_rate") .property("max_rate")
.with_getter(|this: &TTS, _| { .with_getter(|this: &TTS, _| {
let Features { let Features {
rate: rate_supported, rate: rate_supported,
@ -65,7 +176,7 @@ impl TTS {
}) })
.done(); .done();
builder builder
.add_property("normal_rate") .property("normal_rate")
.with_getter(|this: &TTS, _| { .with_getter(|this: &TTS, _| {
let Features { let Features {
rate: rate_supported, rate: rate_supported,
@ -79,73 +190,140 @@ impl TTS {
}) })
.done(); .done();
builder builder
.add_property("can_detect_screen_reader") .property("can_detect_screen_reader")
.with_getter(|_: &TTS, _| if cfg!(windows) { true } else { false }) .with_getter(|_: &TTS, _| cfg!(windows))
.done();
#[allow(unreachable_code)]
builder
.add_property("has_screen_reader")
.with_getter(|_: &TTS, _| {
#[cfg(windows)]
{
let tolk = tolk::Tolk::new();
return tolk.detect_screen_reader().is_some();
}
false
})
.done(); .done();
builder builder
.add_property("can_detect_is_speaking") .property("has_screen_reader")
.with_getter(|_, _| Tts::screen_reader_available())
.done();
builder
.property("can_detect_is_speaking")
.with_getter(|this: &TTS, _| { .with_getter(|this: &TTS, _| {
let Features { let Features {
is_speaking: is_speaking_supported, is_speaking: is_speaking_supported,
.. ..
} = this.0.supported_features(); } = this.0.supported_features();
return is_speaking_supported; is_speaking_supported
}) })
.done(); .done();
builder builder
.add_property("is_speaking") .property("is_speaking")
.with_getter(|this: &TTS, _| { .with_getter(|this: &TTS, _| {
let Features { let Features {
is_speaking: is_speaking_supported, is_speaking: is_speaking_supported,
.. ..
} = this.0.supported_features(); } = this.0.supported_features();
if is_speaking_supported { if is_speaking_supported {
return this.0.is_speaking().unwrap(); this.0
.is_speaking()
.expect("Failed to determine if speaking")
} else { } else {
return false; false
} }
}) })
.done(); .done();
builder
.signal("utterance_begin")
.with_param_custom(SignalParam {
name: "utterance".into(),
default: Variant::default(),
export_info: ExportInfo::new(VariantType::Object),
usage: PropertyUsage::DEFAULT,
})
.done();
builder
.signal("utterance_end")
.with_param_custom(SignalParam {
name: "utterance".into(),
default: Variant::default(),
export_info: ExportInfo::new(VariantType::Object),
usage: PropertyUsage::DEFAULT,
})
.done();
builder
.signal("utterance_stop")
.with_param_custom(SignalParam {
name: "utterance".into(),
default: Variant::default(),
export_info: ExportInfo::new(VariantType::Object),
usage: PropertyUsage::DEFAULT,
})
.done();
} }
#[export] #[method]
fn speak(&mut self, _owner: &Node, message: GodotString, interrupt: bool) { fn speak(&mut self, message: String, interrupt: bool) -> Variant {
let message = message.to_string(); if let Ok(id) = self.0.speak(message, interrupt) {
self.0.speak(message, interrupt).unwrap(); let utterance: Instance<Utterance, Unique> = Instance::new();
if id.is_some() {
utterance
.map_mut(|u, _| u.0 = id)
.expect("Failed to set utterance ID");
}
utterance.owned_to_variant()
} else {
Variant::default()
}
} }
#[export] #[method]
fn stop(&mut self, _owner: &Node) { fn stop(&mut self) {
self.0.stop().unwrap(); self.0.stop().expect("Failed to stop");
} }
#[export] #[method]
fn is_rate_supported(&mut self, _owner: &Node) -> bool { fn is_rate_supported(&mut self) -> bool {
let Features { let Features {
rate: rate_supported, rate: rate_supported,
.. ..
} = self.0.supported_features(); } = self.0.supported_features();
rate_supported rate_supported
} }
#[method]
fn are_utterance_callbacks_supported(&mut self) -> bool {
let Features {
utterance_callbacks: supported,
..
} = self.0.supported_features();
supported
}
#[method]
fn _process(&mut self, #[base] base: &Node, _delta: f32) {
if let Ok(msg) = self.1.try_recv() {
match msg {
Msg::UtteranceBegin(utterance_id) => {
let utterance: Instance<Utterance, Unique> = Instance::new();
utterance
.map_mut(|u, _| u.0 = Some(utterance_id))
.expect("Failed to set utterance ID");
base.emit_signal("utterance_begin", &[utterance.owned_to_variant()]);
}
Msg::UtteranceEnd(utterance_id) => {
let utterance: Instance<Utterance, Unique> = Instance::new();
utterance
.map_mut(|u, _| u.0 = Some(utterance_id))
.expect("Failed to set utterance ID");
base.emit_signal("utterance_end", &[utterance.owned_to_variant()]);
}
Msg::UtteranceStop(utterance_id) => {
let utterance: Instance<Utterance, Unique> = Instance::new();
utterance
.map_mut(|u, _| u.0 = Some(utterance_id))
.expect("Failed to set utterance ID");
base.emit_signal("utterance_stop", &[utterance.owned_to_variant()]);
}
}
}
}
} }
fn init(handle: InitHandle) { fn init(handle: InitHandle) {
env_logger::init(); env_logger::init();
handle.add_tool_class::<Utterance>();
handle.add_class::<TTS>(); handle.add_class::<TTS>();
} }
godot_gdnative_init!(); godot_init!(init);
godot_nativescript_init!(init);
godot_gdnative_terminate!();

View File

@ -1,35 +1,51 @@
package games.lightsout.godot.tts; package games.lightsout.godot.tts;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Set;
import org.godotengine.godot.Godot; import org.godotengine.godot.Godot;
import org.godotengine.godot.plugin.GodotPlugin; import org.godotengine.godot.plugin.GodotPlugin;
import org.godotengine.godot.plugin.SignalInfo;
import android.accessibilityservice.AccessibilityServiceInfo; import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Context; import android.content.Context;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.speech.tts.UtteranceProgressListener;
import android.view.accessibility.AccessibilityManager; import android.view.accessibility.AccessibilityManager;
public class TTS extends GodotPlugin implements TextToSpeech.OnInitListener { public class TTS extends GodotPlugin implements TextToSpeech.OnInitListener {
private TextToSpeech tts = null; private TextToSpeech tts = null;
private float volume = 1f;
private float rate = 1f; private float rate = 1f;
private Integer utteranceId = 0; private Integer utteranceId = 0;
public void speak(String text, boolean interrupt) { public int speak(String text, boolean interrupt) {
int mode = TextToSpeech.QUEUE_ADD; int mode = TextToSpeech.QUEUE_ADD;
if (interrupt) if (interrupt)
mode = TextToSpeech.QUEUE_FLUSH; mode = TextToSpeech.QUEUE_FLUSH;
tts.speak(text, mode, null, this.utteranceId.toString()); tts.speak(text, mode, null, this.utteranceId.toString());
int rv = this.utteranceId.intValue();
this.utteranceId++; this.utteranceId++;
return rv;
} }
public void stop() { public void stop() {
tts.stop(); tts.stop();
} }
public float get_volume() {
return this.volume;
}
public void set_volume(float volume) {
this.volume = volume;
tts.Engine.KEY_PARAM_VOLUME = volume;
}
public float get_rate() { public float get_rate() {
return this.rate; return this.rate;
} }
@ -55,9 +71,32 @@ public class TTS extends GodotPlugin implements TextToSpeech.OnInitListener {
} }
} }
class Listener extends UtteranceProgressListener {
public void onStart(String utteranceId) {
Integer id = Integer.parseInt(utteranceId);
TTS.this.emitSignal("utterance_begin", id);
}
public void onStop(String utteranceId, Boolean interrupted) {
Integer id = Integer.parseInt(utteranceId);
TTS.this.emitSignal("utterance_stop", id);
}
public void onDone(String utteranceId) {
Integer id = Integer.parseInt(utteranceId);
TTS.this.emitSignal("utterance_end", id);
}
public void onError(String utteranceId) {
Integer id = Integer.parseInt(utteranceId);
TTS.this.emitSignal("utterance_end", id);
}
}
public TTS(Godot godot) { public TTS(Godot godot) {
super(godot); super(godot);
this.tts = new TextToSpeech(this.getActivity(), this); this.tts = new TextToSpeech(this.getActivity(), this);
tts.setOnUtteranceProgressListener(new Listener());
} }
@Override @Override
@ -70,6 +109,14 @@ public class TTS extends GodotPlugin implements TextToSpeech.OnInitListener {
return Arrays.asList("speak", "stop", "get_rate", "set_rate", "has_screen_reader", "is_speaking"); return Arrays.asList("speak", "stop", "get_rate", "set_rate", "has_screen_reader", "is_speaking");
} }
@Override
public Set<SignalInfo> getPluginSignals() {
SignalInfo begin = new SignalInfo("utterance_begin", Integer.class);
SignalInfo end = new SignalInfo("utterance_end", Integer.class);
SignalInfo stop = new SignalInfo("utterance_stop", Integer.class);
return new HashSet(Arrays.asList(begin, end, stop));
}
public void onInit(int status) { public void onInit(int status) {
} }