-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathSpeechToTextModule.h
88 lines (67 loc) · 2.73 KB
/
SpeechToTextModule.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// VoiceAddModule.h
// AstridiPhone
//
// Created by Sam Bosley on 10/7/11.
// Copyright (c) 2011 Todoroo. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <AudioToolbox/AudioToolbox.h>
#import <speex/speex.h>
#import "SineWaveViewController.h"
#define kNumberBuffers 3
#define kNumVolumeSamples 10
#define kSilenceThresholdDB -30.0
#define kVolumeSamplingInterval 0.05
#define kSilenceTimeThreshold 0.9
#define kSilenceThresholdNumSamples kSilenceTimeThreshold / kVolumeSamplingInterval
// For scaling display
#define kMinVolumeSampleValue 0.01
#define kMaxVolumeSampleValue 1.0
typedef struct AQRecorderState {
AudioStreamBasicDescription mDataFormat;
AudioQueueRef mQueue;
AudioQueueBufferRef mBuffers[kNumberBuffers];
UInt32 bufferByteSize;
SInt64 mCurrentPacket;
bool mIsRunning;
SpeexBits speex_bits;
void * speex_enc_state;
int speex_samples_per_frame;
__unsafe_unretained NSMutableData * encodedSpeexData;
__unsafe_unretained id selfRef;
} AQRecorderState;
@protocol SpeechToTextModuleDelegate <NSObject>
// Delegate will need to parse JSON and dismiss loading view if presented
// returns true on success, false on failure
- (BOOL)didReceiveVoiceResponse:(NSData *)data;
@optional
- (void)showSineWaveView:(SineWaveViewController *)view;
- (void)dismissSineWaveView:(SineWaveViewController *)view cancelled:(BOOL)wasCancelled;
- (void)showLoadingView;
@end
@interface SpeechToTextModule : NSObject <UIAlertViewDelegate, SineWaveViewDelegate> {
UIAlertView *status;
AQRecorderState aqData;
BOOL detectedSpeech;
int samplesBelowSilence;
NSTimer *meterTimer;
BOOL processing;
NSMutableArray *volumeDataPoints;
SineWaveViewController *sineWave;
NSThread *processingThread;
}
@property (readonly) BOOL recording;
@property (assign) id<SpeechToTextModuleDelegate> delegate;
/* Caller can pass a non-nil nib name to specify the nib with which to create
a SineWaveViewController (nib should conform to the spec in the SineWaveViewController
interface). A nil argument will cause the module to display an alert view instead
of the custom view controller. */
- (id)initWithCustomDisplay:(NSString *)nibName;
// Begins a voice recording
- (void)beginRecording;
// Stops a voice recording. The startProcessing parameter is intended for internal use,
// so don't pass NO unless you really mean it.
- (void)stopRecording:(BOOL)startProcessing;
@end