// FILE:      Speech.m
// AUTHOR:    Daniel Lee
// PURPOSE:   
// REFERENCE: None. 
// COMMENTS:  
// REQUIRES:  Speech.h
// Last Mod:  23-03-2006




#import "Speech.h"

@implementation Speech


// NAME: init
// PURPOSE: To initialize this object and the Synthesizer. It will also speak to the user with an intro.
// IMPORTS: nil
// EXPORTS: nil
// REMARKS: The default voice is used as to let the user be more comfortable with the program.
// LAST MODIFIED: 21-03-2006

- (id) init
{
    self = [super init];
    if ( self )
	{
        synth = [[NSSpeechSynthesizer alloc] init]; //Allow the default voice to be used.
        [synth setDelegate:self];
        [synth startSpeakingString: @"Welcome to the Braille Converter."];
		NSLog( @"Speech active");
    }
	
    return self;
}


// NAME: speak
// PURPOSE: To speak the given text
// IMPORTS: textToSpeak
// EXPORTS: nil
// REMARKS: 
// LAST MODIFIED: 21-03-2006

- (void) speak: (NSString*) textToSpeak
{

    // If something new is put in, stop it (with the synth hopefully discarding
	// the old text) and speak the newer one.

    if( [synth isSpeaking] )
	{
	    [synth stopSpeaking];
	}
    [synth startSpeakingString:textToSpeak];
    NSLog( @"Spoke: %@", textToSpeak);
}

- (void) delloc
{
    [synth release];
}


@end
