'SpeechSynthesis in Big Sur
I'm running MacOS 11.6.1 on an M1 Mac. Trying to compile a simple text-to-speech program using GCC in a Terminal window.
Make file is: gcc vocabTest.c -o vocab
It compiles, but won't link. Have tried g++. Have tried -arch x86_64. Keep getting error:
Undefined symbols for architecture arm64: "_CFStringCreateWithCString", referenced from: etc
Am I missing libraries?
Any help greatly appreciated. I'm strictly an amateur at programming. Thanks.
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#import <Carbon/Carbon.h>
// #include "SpeechSynthesis.h"
int main(void)
{
char text[120] = "Hello, World"; /* lines, S/E, chars */
SpeechChannel chan;
CFStringRef aString;
aString = CFStringCreateWithCString(NULL, text, kCFStringEncodingMacRoman);
printf("text = %s\n", text);
SpeakCFString(chan, aString, NULL);
return(0);
}
Solution 1:[1]
My thanks to those who responded. It helped set me on the path to find an answer. I, indeed, needed to link libraries. Here is the final, working MakeFile and Code.
gcc vocabTest.c -o vocab -framework Carbon
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#import <Carbon/Carbon.h>
int main(void)
{
char text[120] = "Hello, World"; /* lines, S/E, chars */
SpeechChannel chan;
CFStringRef aString;
OSErr theErr = noErr;
theErr = NewSpeechChannel(NULL, &chan);
aString = CFStringCreateWithCString(NULL, text, kCFStringEncodingMacRoman);
SpeakCFString(chan, aString, NULL);
while (SpeechBusySystemWide());
return(0);
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | RodC |
