Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Altair89

macrumors newbie
Original poster
May 23, 2007
4
0
First off, hello everyone.

Secondly: I have a pretty simple desire, i want you use Mac OS X's 'say' utility in either python or c++. (ex. in terminal type "say Hello World")

I basically want to make a small program to manipulate text strings and pass them to the say utility while the program continues to run. I have some (limited) experience to python and C++ so which ever is easiest I'll choose to use.

Any advice? I'll be sure to post the final project, i imagine some of you would enjoy it :).

Thanks!
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
This is C. I can try to adapt it to C++ using strings instead of char *, but the concept is the same:
Code:
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[]) {
  char command[2048];
  int len;
  if(argc < 2) {
    printf("Usage: runsay \"String to speak\"\n");
    return -1;
  }
  len = strlen(argv[1]);
  if(len > 2040) {
    printf("Please enter a string to say that is less than 2040 characters.\n");
    return -2;
  }
  snprintf(command,2048,"say \"%s\"&",argv[1]);
  system(command);
  return 0;
}

-Lee

Edit:
Worked up a C++ version:
Code:
#include <iostream>
#include <string>

using namespace std;
int main(int argc, char *argv[]) {
  string command = "say \"";
  if(argc < 2) {
    cout << "Usage: runsay++ \"String to say\"" << endl;
    return -1;
  }
  command.append(argv[1]);
  command.append("\"&");
  system(command.c_str());
  return 0;
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.