mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
More work on winspeech
This commit is contained in:
parent
4cab9b598e
commit
3ae27e38f3
@ -127,14 +127,15 @@ ensure_current_thread_has_message_queue(void) {
|
|||||||
PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
|
PeekMessage(&msg, NULL, WM_USER, WM_USER, PM_NOREMOVE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PREPARE_METHOD_CALL ensure_current_thread_has_message_queue(); if (GetCurrentThreadId() != self->creation_thread_id) { PyErr_SetString(PyExc_RuntimeError, "Cannot use a Synthesizer object from a thread other than the thread it was created in"); return NULL; }
|
||||||
|
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
Synthesizer_speak(Synthesizer *self, PyObject *args) {
|
Synthesizer_speak(Synthesizer *self, PyObject *args) {
|
||||||
|
PREPARE_METHOD_CALL;
|
||||||
wchar_raii pytext;
|
wchar_raii pytext;
|
||||||
PyObject *callback;
|
|
||||||
int is_ssml = 0;
|
int is_ssml = 0;
|
||||||
if (!PyArg_ParseTuple(args, "O&O|p", py_to_wchar_no_none, &pytext, &callback, &is_ssml)) return NULL;
|
if (!PyArg_ParseTuple(args, "O&|p", py_to_wchar_no_none, &pytext, &is_ssml)) return NULL;
|
||||||
if (!PyCallable_Check(callback)) { PyErr_SetString(PyExc_TypeError, "callback must be callable"); return NULL; }
|
|
||||||
ensure_current_thread_has_message_queue();
|
|
||||||
SpeechSynthesisStream stream{nullptr};
|
SpeechSynthesisStream stream{nullptr};
|
||||||
try {
|
try {
|
||||||
if (is_ssml) stream = self->synth.SynthesizeSsmlToStreamAsync(pytext.as_view()).get();
|
if (is_ssml) stream = self->synth.SynthesizeSsmlToStreamAsync(pytext.as_view()).get();
|
||||||
@ -151,13 +152,13 @@ Synthesizer_speak(Synthesizer *self, PyObject *args) {
|
|||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
Synthesizer_create_recording(Synthesizer *self, PyObject *args) {
|
Synthesizer_create_recording(Synthesizer *self, PyObject *args) {
|
||||||
|
PREPARE_METHOD_CALL;
|
||||||
wchar_raii pytext;
|
wchar_raii pytext;
|
||||||
PyObject *callback;
|
PyObject *callback;
|
||||||
int is_ssml = 0;
|
int is_ssml = 0;
|
||||||
if (!PyArg_ParseTuple(args, "O&O|p", py_to_wchar_no_none, &pytext, &callback, &is_ssml)) return NULL;
|
if (!PyArg_ParseTuple(args, "O&O|p", py_to_wchar_no_none, &pytext, &callback, &is_ssml)) return NULL;
|
||||||
if (!PyCallable_Check(callback)) { PyErr_SetString(PyExc_TypeError, "callback must be callable"); return NULL; }
|
if (!PyCallable_Check(callback)) { PyErr_SetString(PyExc_TypeError, "callback must be callable"); return NULL; }
|
||||||
|
|
||||||
ensure_current_thread_has_message_queue();
|
|
||||||
SpeechSynthesisStream stream{nullptr};
|
SpeechSynthesisStream stream{nullptr};
|
||||||
try {
|
try {
|
||||||
if (is_ssml) stream = self->synth.SynthesizeSsmlToStreamAsync(pytext.as_view()).get();
|
if (is_ssml) stream = self->synth.SynthesizeSsmlToStreamAsync(pytext.as_view()).get();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user