mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Code to set the voice and audio device
This commit is contained in:
parent
e8f07e273b
commit
ad9cf1b0f6
@ -554,14 +554,12 @@ handle_speak(id_type cmd_id, std::vector<std::wstring_view> &parts) {
|
|||||||
*((wchar_t*)text.data() + text.size()) = 0; // ensure NULL termination
|
*((wchar_t*)text.data() + text.size()) = 0; // ensure NULL termination
|
||||||
|
|
||||||
output(cmd_id, "synthesizing", {{"ssml", is_ssml}, {"num_marks", marks->entries.size()}, {"text_length", text.size()}});
|
output(cmd_id, "synthesizing", {{"ssml", is_ssml}, {"num_marks", marks->entries.size()}, {"text_length", text.size()}});
|
||||||
bool ok = false;
|
|
||||||
SpeechSynthesisStream stream{nullptr};
|
SpeechSynthesisStream stream{nullptr};
|
||||||
if (!run_catching_exceptions([&]() {
|
if (!run_catching_exceptions([&]() {
|
||||||
speech_synthesizer.Options().IncludeSentenceBoundaryMetadata(true);
|
speech_synthesizer.Options().IncludeSentenceBoundaryMetadata(true);
|
||||||
speech_synthesizer.Options().IncludeWordBoundaryMetadata(true);
|
speech_synthesizer.Options().IncludeWordBoundaryMetadata(true);
|
||||||
if (is_ssml) stream = speech_synthesizer.SynthesizeSsmlToStreamAsync(text).get();
|
if (is_ssml) stream = speech_synthesizer.SynthesizeSsmlToStreamAsync(text).get();
|
||||||
else stream = speech_synthesizer.SynthesizeTextToStreamAsync(text).get();
|
else stream = speech_synthesizer.SynthesizeTextToStreamAsync(text).get();
|
||||||
ok = true;
|
|
||||||
}, "Failed to synthesize speech", __LINE__, cmd_id)) return;
|
}, "Failed to synthesize speech", __LINE__, cmd_id)) return;
|
||||||
|
|
||||||
speak_revoker = {}; // delete any revokers previously installed
|
speak_revoker = {}; // delete any revokers previously installed
|
||||||
@ -710,6 +708,29 @@ static const std::unordered_map<std::string, handler_function> handlers = {
|
|||||||
handle_speak(cmd_id, parts);
|
handle_speak(cmd_id, parts);
|
||||||
}},
|
}},
|
||||||
|
|
||||||
|
{"audio_device", [](id_type cmd_id, std::vector<std::wstring_view> parts, int64_t*) {
|
||||||
|
if (parts.size()) {
|
||||||
|
auto di = DeviceInformation::CreateFromIdAsync(parts[0]).get();
|
||||||
|
media_player.AudioDevice(di);
|
||||||
|
}
|
||||||
|
output(cmd_id, "audio_device", {{"value", media_player.AudioDevice()}});
|
||||||
|
}},
|
||||||
|
|
||||||
|
{"voice", [](id_type cmd_id, std::vector<std::wstring_view> parts, int64_t*) {
|
||||||
|
bool found = false;
|
||||||
|
if (parts.size()) {
|
||||||
|
auto voice_id = winrt::hstring(parts[0]);
|
||||||
|
for (auto const &candidate : SpeechSynthesizer::AllVoices()) {
|
||||||
|
if (candidate.Id() == voice_id) {
|
||||||
|
speech_synthesizer.Voice(candidate);
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output(cmd_id, "voice", {{"value", speech_synthesizer.Voice()}, {"found", found}});
|
||||||
|
}},
|
||||||
|
|
||||||
{"volume", [](id_type cmd_id, std::vector<std::wstring_view> parts, int64_t*) {
|
{"volume", [](id_type cmd_id, std::vector<std::wstring_view> parts, int64_t*) {
|
||||||
if (parts.size()) {
|
if (parts.size()) {
|
||||||
auto vol = parse_double(parts[0].data());
|
auto vol = parse_double(parts[0].data());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user