Vuo  2.3.2
VuoSpeechVoice.m
Go to the documentation of this file.
1 
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <string.h>
13 #include "type.h"
14 #include "VuoSpeechVoice.h"
15 #include "VuoList_VuoSpeechVoice.h"
16 
17 #include "VuoMacOSSDKWorkaround.h"
18 #include <AppKit/AppKit.h>
19 
21 #ifdef VUO_COMPILER
23  "title" : "Speech Voice",
24  "description" : "An identifier for a speech synthesizer voice.",
25  "keywords" : [ ],
26  "version" : "1.0.0",
27  "dependencies" : [
28  "VuoText",
29  "VuoList_VuoSpeechVoice"
30  ]
31 });
32 #endif
34 
43 {
44  const char *valueAsString = "";
45  if (json_object_get_type(js) == json_type_string)
46  valueAsString = json_object_get_string(js);
47  return VuoText_make(valueAsString);
48 }
49 
54 {
55  return VuoText_getJson(value);
56 }
57 
62 {
63  NSArray *voices = [NSSpeechSynthesizer availableVoices];
64  int voiceCount = [voices count];
65 
67  for (int i = 0; i < voiceCount; ++i)
68  {
69  NSDictionary *voiceAttributes = [NSSpeechSynthesizer attributesForVoice:[voices objectAtIndex:i]];
70 
71  // I tried filtering by VoiceShowInFullListOnly,
72  // but it doesn't seem to have any correlation to whether the voice's checkbox is checked in
73  // System Preferences > Accessibility > Speech > System Voice > Customize.
74 // NSNumber *n = [voiceAttributes objectForKey:@"VoiceShowInFullListOnly"];
75 // if (n && [n integerValue] == 0)
76 // continue;
77 
78  VuoListAppendValue_VuoSpeechVoice(l, VuoText_make([[voiceAttributes objectForKey:NSVoiceIdentifier] UTF8String]));
79  }
80 
81  return l;
82 }
83 
88 {
89  if (VuoText_isEmpty(value))
90  goto bad;
91 
92  NSString *voiceName = [NSString stringWithUTF8String:value];
93  if (!voiceName)
94  goto bad;
95 
96  NSDictionary *voiceAttributes = [NSSpeechSynthesizer attributesForVoice:voiceName];
97  if (!voiceAttributes)
98  goto bad;
99 
100  const char *actualVoiceName = [[voiceAttributes objectForKey:NSVoiceName] UTF8String];
101  if (!actualVoiceName)
102  goto bad;
103 
104  return strdup(actualVoiceName);
105 
106 bad:
107  return strdup("No voice");
108 }
109 
113 bool VuoSpeechVoice_areEqual(const VuoSpeechVoice valueA, const VuoSpeechVoice valueB)
114 {
115  return VuoText_areEqual(valueA, valueB);
116 }
117 
122 {
123  return VuoText_isLessThan(valueA, valueB);
124 }