Implement rate control

This commit is contained in:
Kovid Goyal 2023-01-28 13:01:21 +05:30
parent 96de7a653d
commit ae3c33ec8c
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -442,12 +442,27 @@ class Synthesizer {
} }
} }
double volume() const { return synth.Options().AudioVolume(); } double volume() const {
return synth.Options().AudioVolume();
}
void volume(double val) { void volume(double val) {
if (val < 0 || val > 1) throw std::out_of_range("Invalid volume value must be between 0 and 1"); if (val < 0 || val > 1) throw std::out_of_range("Invalid volume value must be between 0 and 1");
std::scoped_lock sl(recursive_lock);
synth.Options().AudioVolume(val); synth.Options().AudioVolume(val);
} }
double rate() const {
return synth.Options().SpeakingRate();
}
void rate(double val) {
if (val < 0.5 || val > 6.0) throw std::out_of_range("Invalid rate value must be between 0.5 and 6");
std::scoped_lock sl(recursive_lock);
synth.Options().SpeakingRate(val);
}
}; };
static Synthesizer sx; static Synthesizer sx;
@ -789,6 +804,13 @@ handle_stdin_message(winrt::hstring const &&msg) {
} }
output(cmd_id, "volume", {{"value", sx.volume()}}); output(cmd_id, "volume", {{"value", sx.volume()}});
} }
else if (command == L"rate") {
if (parts.size()) {
auto rate = parse_double(parts[0].data());
sx.rate(rate);
}
output(cmd_id, "rate", {{"value", sx.rate()}});
}
else if (command == L"save") { else if (command == L"save") {
handle_save(cmd_id, parts); handle_save(cmd_id, parts);
} }