//
//  CedatSTTManager.h
//  CedatSTT
//
//  Created by Gennaro Stanzione on 04/07/17.
//  Copyright © 2017 Cedat85. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import "CedatSTTHypothesis.h"

@protocol CedatSTTManagerDelegate;

@interface CedatSTTManager : NSObject

/*!
 *  Singleton instance
 */
+ (CedatSTTManager * _Nonnull) shared;

#pragma mark - Properties

/*!
 *  The Api Key (string) used for the authentication for the speech to text service.
 *  This property is mandatory in order to use the service.
 */
@property (nonatomic, strong, nonnull) NSString *apiKey;

/*!
 *  The URL (string) used for the speech to text service.
 *  The default value is "ws://voicenote.trascrivi.com/ws/client/speech"
 */
@property (nonatomic, strong, nonnull) NSString *decoderUrl;

/*!
 *  The message that will be displayed inside the alert view. The default value is "Parla ora".
 */
@property (nonatomic, strong, nonnull) NSString *prompt;

/*!
 *  Maximum number of results. It must be greater than zero.
 *  The default value is 1
 */
@property (nonatomic, assign) NSInteger maxResults;

/*!
 *  Minimum silence duration to detect the endpoint, in seconds. It must be greater than zero.
 *  The default value is 2.0
 */
@property (nonatomic, assign) float minSilence;

/*!
 *  Specify the language model.
 *  The default value is "it-IT_8k"
 */
@property (nonatomic, strong, nonnull) NSString *languageModel;


/*!
 *  The URL used for the speech to text service.
 */
@property (nonatomic, readonly, nonnull) NSURL *serviceURL;


/*!
 *  Delegate instance, to assign in order to receive the recognized text, or an error occurred.
 */
@property (nonatomic, weak, nullable) id<CedatSTTManagerDelegate> delegate;


/*!
 *  The view controller to present to start the speech to text recognition.
 */
@property (nonatomic, strong, readonly, nullable) UIViewController *cedatSTTViewController;


/*!
 *  Call this method to trigger the speech to text recognition.
 */
- (void) startRecognize;
    
/*!
 *  Call this method to force the stop of the speech to text recognition service.
 */
- (void) stopRecognize;

/*!
 *  Call this method if you want to know if the speech to text recognition is active.
 *  Returns true if the service is active, false otherwise.
 */
- (BOOL) isRecognizing;


@end

@protocol CedatSTTManagerDelegate <NSObject>

/*!
 *  Called when the recognition is finished with some results.
 */
- (void) cedatSTTManager:(CedatSTTManager * _Nonnull) manager didRecognizeAudioWith:(NSArray<CedatSTTHypothesis *> * _Nonnull) hypotheses;
    
/*!
 *  Called when a partial recognition is available.
 */
- (void) cedatSTTManager:(CedatSTTManager * _Nonnull) manager didRecognizePartialAudioWith:(NSString * _Nonnull) partialRecognizedText;

/*!
 *  Called when an error occurred.
 */
- (void) cedatSTTManager:(CedatSTTManager * _Nonnull) manager didFailRecognizeAudioWithError:(NSString * _Nonnull)error;

/*!
 *  Called when the volume change.
 */
- (void) cedatSTTManager:(CedatSTTManager * _Nonnull) manager didChangeVolumeWithDecibels:(float) decibels;

@end
