// FILE:      Speech.m
// AUTHOR:    Daniel Lee
// PURPOSE:   
// REFERENCE: None. 
// COMMENTS:  
// REQUIRES:  Speech.h
// Last Mod:  05-04-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
// AUTHOR: Daniel Lee
// REMARKS: The default voice is used as to let the user be more comfortable with the program.
// LAST MODIFIED: 05-04-2006

- (id) init
{
    self = [super init];
    if ( self )
    {
        synth = [[NSSpeechSynthesizer alloc] init];    // Allow the default voice to be used.
        // Set the delegate as self to make this object the one which does anything
        [synth setDelegate: self];
        [synth startSpeakingString: @"Welcome to the Braille Converter."];

        // To put to the logs to see if the speech is working
        if( [synth isSpeaking] )
        {
            NSLog( @"Speech active");
        }
        else
        {
            NSLog( @"Speech seems to be disabled");
        }
    }

    return self;
}


// NAME: speak
// PURPOSE: To speak the given text
// IMPORTS: NSString textToSpeak
// EXPORTS: nil
// AUTHOR: Daniel Lee
// REMARKS: 
// LAST MODIFIED: 05-04-2006

- (void) speak: (NSString*) textToSpeak
{
    // If a new text to speak is parsed in, stop it (with the synthisizer discarding
    // the old text) and speak the newer one.

    if( [synth isSpeaking] )
    {
        [synth stopSpeaking];
    }

    [synth startSpeakingString: textToSpeak];
    
    // Log what has been spoken
    // NSLog( @"Spoke: %@", textToSpeak);
}


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


@end
