mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix voice enumeration
This commit is contained in:
parent
6adf45f81f
commit
084de4c88d
@ -37,6 +37,20 @@ NSSS_dealloc(NSSS *self) {
|
|||||||
self->nsss = nil;
|
self->nsss = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static PyObject*
|
||||||
|
as_python(NSObject *x) {
|
||||||
|
if (!x) Py_RETURN_NONE;
|
||||||
|
if ([x isKindOfClass:[NSString class]]) {
|
||||||
|
NSString *s = (NSString*)x;
|
||||||
|
return PyUnicode_FromString([s UTF8String]);
|
||||||
|
}
|
||||||
|
if ([x isKindOfClass:[NSNumber class]]) {
|
||||||
|
NSNumber *n = (NSNumber*)x;
|
||||||
|
return PyFloat_FromDouble([n doubleValue]);
|
||||||
|
}
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
NSSS_get_all_voices(NSSS *self, PyObject *args) {
|
NSSS_get_all_voices(NSSS *self, PyObject *args) {
|
||||||
PyObject *ans = PyDict_New();
|
PyObject *ans = PyDict_New();
|
||||||
@ -44,13 +58,10 @@ NSSS_get_all_voices(NSSS *self, PyObject *args) {
|
|||||||
for (NSSpeechSynthesizerVoiceName voice_id in [NSSpeechSynthesizer availableVoices]) {
|
for (NSSpeechSynthesizerVoiceName voice_id in [NSSpeechSynthesizer availableVoices]) {
|
||||||
NSDictionary *attributes = [NSSpeechSynthesizer attributesForVoice:voice_id];
|
NSDictionary *attributes = [NSSpeechSynthesizer attributesForVoice:voice_id];
|
||||||
if (attributes) {
|
if (attributes) {
|
||||||
NSString *name = [attributes objectForKey:NSVoiceName];
|
#define E(x, y) #x, as_python([attributes objectForKey:y])
|
||||||
NSString *age = [attributes objectForKey:NSVoiceAge];
|
PyObject *v = Py_BuildValue("{sN sN sN sN sN}",
|
||||||
NSString *gender = [attributes objectForKey:NSVoiceGender];
|
E(name, NSVoiceName), E(age, NSVoiceAge), E(gender, NSVoiceGender),
|
||||||
NSString *demo_text = [attributes objectForKey:NSVoiceDemoText];
|
E(demo_text, NSVoiceDemoText), E(locale_id, NSVoiceLocaleIdentifier));
|
||||||
NSString *locale_id = [attributes objectForKey:NSVoiceLocaleIdentifier];
|
|
||||||
#define E(x) #x, (x ? [x UTF8String] : NULL)
|
|
||||||
PyObject *v = Py_BuildValue("{ss ss ss ss ss}", E(name), E(age), E(gender), E(demo_text), E(locale_id));
|
|
||||||
if (!v) { Py_DECREF(ans); return NULL; }
|
if (!v) { Py_DECREF(ans); return NULL; }
|
||||||
#undef E
|
#undef E
|
||||||
if (PyDict_SetItemString(ans, [voice_id UTF8String], v) != 0) {
|
if (PyDict_SetItemString(ans, [voice_id UTF8String], v) != 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user