mirror of
https://github.com/lightsoutgames/godot-tts
synced 2024-11-22 11:05:56 +00:00
Make rate
a percentage, and add getter to determine if rate selection is supported.
This commit is contained in:
parent
f6cf82f8c9
commit
1bb0f56f40
7
TTS.gd
7
TTS.gd
|
@ -1,3 +1,4 @@
|
|||
tool
|
||||
extends Node
|
||||
|
||||
const TTS = preload("godot-tts.gdns")
|
||||
|
@ -11,12 +12,18 @@ func get_rate():
|
|||
return tts.rate
|
||||
|
||||
var rate setget set_rate, get_rate
|
||||
|
||||
func speak(text, interrupt := true):
|
||||
tts.speak(text, interrupt)
|
||||
|
||||
func stop():
|
||||
tts.stop()
|
||||
|
||||
func get_is_rate_supported():
|
||||
return tts.is_rate_supported()
|
||||
|
||||
var is_rate_supported setget , get_is_rate_supported
|
||||
|
||||
func singular_or_plural(count, singular, plural):
|
||||
if count == 1:
|
||||
return singular
|
||||
|
|
22
src/lib.rs
22
src/lib.rs
|
@ -1,7 +1,8 @@
|
|||
use std::u8;
|
||||
|
||||
use gdnative::*;
|
||||
use gdnative::init::*;
|
||||
|
||||
use tts::{TTS as Tts};
|
||||
use tts::{Features, TTS as Tts};
|
||||
|
||||
struct TTS(Tts);
|
||||
|
||||
|
@ -20,18 +21,19 @@ impl NativeClass for TTS {
|
|||
fn register_properties(builder: &ClassBuilder<Self>) {
|
||||
builder.add_property(Property {
|
||||
name: "rate",
|
||||
default: 128,
|
||||
default: 50,
|
||||
hint: PropertyHint::Range {
|
||||
range: 0.0..255.0,
|
||||
range: 0.0..100.0,
|
||||
step: 1.,
|
||||
slider: true,
|
||||
},
|
||||
getter: |this: &TTS| {
|
||||
let rate = this.0.get_rate().unwrap();
|
||||
rate
|
||||
rate / u8::MAX * 100
|
||||
},
|
||||
setter: |this: &mut TTS, v: u8| {
|
||||
this.0.set_rate(v).unwrap();
|
||||
let v = v / 100 * u8::MAX;
|
||||
this.0.set_rate(v as u8).unwrap();
|
||||
},
|
||||
usage: PropertyUsage::DEFAULT,
|
||||
});
|
||||
|
@ -56,6 +58,14 @@ impl TTS {
|
|||
fn stop(&mut self, _owner: Node) {
|
||||
self.0.stop().unwrap();
|
||||
}
|
||||
|
||||
#[export]
|
||||
fn is_rate_supported(&mut self, _owner: Node) -> bool {
|
||||
let Features {
|
||||
rate: rate_feature, ..
|
||||
} = self.0.supported_features();
|
||||
rate_feature
|
||||
}
|
||||
}
|
||||
|
||||
fn init(handle: gdnative::init::InitHandle) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user