Vuo  2.0.0
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 #ifndef NS_RETURNS_INNER_POINTER
18 #define NS_RETURNS_INNER_POINTER
19 #endif
20 #include <Cocoa/Cocoa.h>
21 
23 #ifdef VUO_COMPILER
25  "title" : "Speech Voice",
26  "description" : "An identifier for a speech synthesizer voice.",
27  "keywords" : [ ],
28  "version" : "1.0.0",
29  "dependencies" : [
30  "VuoText",
31  "VuoList_VuoSpeechVoice"
32  ]
33 });
34 #endif
35 
45 {
46  const char *valueAsString = "";
47  if (json_object_get_type(js) == json_type_string)
48  valueAsString = json_object_get_string(js);
49  return VuoText_make(valueAsString);
50 }
51 
56 {
57  return VuoText_getJson(value);
58 }
59 
64 {
65  NSArray *voices = [NSSpeechSynthesizer availableVoices];
66  int voiceCount = [voices count];
67 
69  for (int i = 0; i < voiceCount; ++i)
70  {
71  NSDictionary *voiceAttributes = [NSSpeechSynthesizer attributesForVoice:[voices objectAtIndex:i]];
72 
73  // I tried filtering by VoiceShowInFullListOnly,
74  // but it doesn't seem to have any correlation to whether the voice's checkbox is checked in
75  // System Preferences > Accessibility > Speech > System Voice > Customize.
76 // NSNumber *n = [voiceAttributes objectForKey:@"VoiceShowInFullListOnly"];
77 // if (n && [n integerValue] == 0)
78 // continue;
79 
80  VuoListAppendValue_VuoSpeechVoice(l, VuoText_make([[voiceAttributes objectForKey:NSVoiceIdentifier] UTF8String]));
81  }
82 
83  return l;
84 }
85 
90 {
91  if (VuoText_isEmpty(value))
92  goto bad;
93 
94  NSString *voiceName = [NSString stringWithUTF8String:value];
95  if (!voiceName)
96  goto bad;
97 
98  NSDictionary *voiceAttributes = [NSSpeechSynthesizer attributesForVoice:voiceName];
99  if (!voiceAttributes)
100  goto bad;
101 
102  const char *actualVoiceName = [[voiceAttributes objectForKey:NSVoiceName] UTF8String];
103  if (!actualVoiceName)
104  goto bad;
105 
106  return strdup(actualVoiceName);
107 
108 bad:
109  return strdup("No voice");
110 }
111 
115 bool VuoSpeechVoice_areEqual(const VuoSpeechVoice valueA, const VuoSpeechVoice valueB)
116 {
117  return VuoText_areEqual(valueA, valueB);
118 }
119 
124 {
125  return VuoText_isLessThan(valueA, valueB);
126 }