Home
Products
Community
Manuals
Contact
Login or Signup

Code archives/Audio/OSX text to speech

This code has been declared by its author to be Public Domain code.

Download source code

OSX text to speech by deps(Posted 1+ years ago)
Simple module that adds text to speech to your blitzmax game under OSX.

Doesn't support different voices or other settings, it uses you default system settings. It's also quite simple and may contain bugs. My first real attempt at OSX programming in c/c++.

Updated. It now compiles under BlitzMax 1.14

Simple usage example:
Strict

' Init text to speech
If Not speech_init() Then
	Notify "Unable to init text to speech."
	End
EndIf

' Talk
speak_string("Hello Macintosh users.")

' Wait until the mac is done talking.
wait_for_speech()



The module:
Strict
Module Deps.osxspeech

ModuleInfo "Name: OSX Text To Speech"
ModuleInfo "Description: You can make you mac talk with this one"
ModuleInfo "License: Public Domain"
ModuleInfo "Authors: Peter Sundling"
ModuleInfo "Updated: 2 Januari 2006 - Compiles under BlitzMax 1.14"

Import "speechmod.c"

Extern "C"	

	Function speech_init:Int()	
	Function speak_string(msg$z)	
	Function wait_for_speech()
	
End Extern



speechmod.c
#include <Carbon/Carbon.h>

int speech_init()
{
	long response, mask;
	OSErr err = Gestalt( gestaltSpeechAttr, &response );
	if ( err != noErr )
	{
		return 0;
	}

	mask = 1 << gestaltSpeechMgrPresent;	
	if ( response & mask == 0 )
 	{
		return 0;
	}

	return 1;
}

void speak_string( char *msg )
{
	OSErr err;
	SpeechChannel ch;
	err = NewSpeechChannel( 0, &ch );

	err = SpeakText( ch, msg, strlen(msg) );

	if( err != noErr )
	{
		return;
	}

}

void wait_for_speech()
{
	while( SpeechBusy() )
		;
}

Comments

deps(Posted 1+ years ago)
Made with BlitzMax 1.10, OSX 10.3.9.


DannyD(Posted 1+ years ago)
I'm having problems getting this to work... details at: http://www.blitzbasic.com/Community/posts.php?topic=54941


DannyD(Posted 1+ years ago)
Everything working just fine now, thanks.


Code Archives Forum