ggerganov commited on
Commit
681b6fe
·
1 Parent(s): f638e82

objc : polishing the sample application

Browse files
examples/whisper.objc/whisper.objc/Base.lproj/Main.storyboard CHANGED
@@ -17,7 +17,7 @@
17
  <autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMinY="YES" heightSizable="YES"/>
18
  <subviews>
19
  <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="VOi-PT-Rbu">
20
- <rect key="frame" x="35" y="121" width="156" height="34"/>
21
  <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
22
  <color key="backgroundColor" systemColor="opaqueSeparatorColor"/>
23
  <color key="tintColor" systemColor="opaqueSeparatorColor"/>
@@ -35,8 +35,16 @@
35
  <nil key="textColor"/>
36
  <nil key="highlightedColor"/>
37
  </label>
 
 
 
 
 
 
 
 
38
  <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="Brs-xi-o8i">
39
- <rect key="frame" x="35" y="177" width="156" height="34"/>
40
  <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
41
  <color key="backgroundColor" systemColor="opaqueSeparatorColor"/>
42
  <color key="tintColor" systemColor="opaqueSeparatorColor"/>
@@ -48,14 +56,6 @@
48
  <action selector="onTranscribePrepare:" destination="BYZ-38-t0r" eventType="touchDown" id="16T-dN-dfB"/>
49
  </connections>
50
  </button>
51
- <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" text="Record some speech and press &quot;Transcribe&quot;. The result will be displayed here." textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="mv2-KD-7jn">
52
- <rect key="frame" x="35" y="248" width="320" height="300"/>
53
- <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
54
- <color key="backgroundColor" systemColor="systemBackgroundColor"/>
55
- <color key="textColor" systemColor="labelColor"/>
56
- <fontDescription key="fontDescription" type="system" pointSize="14"/>
57
- <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
58
- </textView>
59
  </subviews>
60
  <viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
61
  <color key="backgroundColor" systemColor="systemBackgroundColor"/>
@@ -64,6 +64,7 @@
64
  </constraints>
65
  </view>
66
  <connections>
 
67
  <outlet property="buttonTranscribe" destination="Brs-xi-o8i" id="N8h-9W-ywb"/>
68
  <outlet property="labelStatusInp" destination="Tgu-2q-eHQ" id="1hH-Ql-K6j"/>
69
  <outlet property="textviewResult" destination="mv2-KD-7jn" id="RBw-0L-iGj"/>
 
17
  <autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMinY="YES" heightSizable="YES"/>
18
  <subviews>
19
  <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="VOi-PT-Rbu">
20
+ <rect key="frame" x="35" y="121" width="156" height="49"/>
21
  <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
22
  <color key="backgroundColor" systemColor="opaqueSeparatorColor"/>
23
  <color key="tintColor" systemColor="opaqueSeparatorColor"/>
 
35
  <nil key="textColor"/>
36
  <nil key="highlightedColor"/>
37
  </label>
38
+ <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" text="Record some speech and press &quot;Transcribe&quot;. The result will be displayed here." textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="mv2-KD-7jn">
39
+ <rect key="frame" x="35" y="248" width="320" height="300"/>
40
+ <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
41
+ <color key="backgroundColor" systemColor="systemBackgroundColor"/>
42
+ <color key="textColor" systemColor="labelColor"/>
43
+ <fontDescription key="fontDescription" type="system" pointSize="20"/>
44
+ <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
45
+ </textView>
46
  <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="Brs-xi-o8i">
47
+ <rect key="frame" x="35" y="191" width="156" height="49"/>
48
  <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
49
  <color key="backgroundColor" systemColor="opaqueSeparatorColor"/>
50
  <color key="tintColor" systemColor="opaqueSeparatorColor"/>
 
56
  <action selector="onTranscribePrepare:" destination="BYZ-38-t0r" eventType="touchDown" id="16T-dN-dfB"/>
57
  </connections>
58
  </button>
 
 
 
 
 
 
 
 
59
  </subviews>
60
  <viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
61
  <color key="backgroundColor" systemColor="systemBackgroundColor"/>
 
64
  </constraints>
65
  </view>
66
  <connections>
67
+ <outlet property="buttonToggleCapture" destination="VOi-PT-Rbu" id="nis-VC-DQO"/>
68
  <outlet property="buttonTranscribe" destination="Brs-xi-o8i" id="N8h-9W-ywb"/>
69
  <outlet property="labelStatusInp" destination="Tgu-2q-eHQ" id="1hH-Ql-K6j"/>
70
  <outlet property="textviewResult" destination="mv2-KD-7jn" id="RBw-0L-iGj"/>
examples/whisper.objc/whisper.objc/ViewController.m CHANGED
@@ -84,6 +84,9 @@ void AudioInputCallback(void * inUserData,
84
 
85
  _labelStatusInp.text = @"Status: Idle";
86
 
 
 
 
87
  stateInp.isCapturing = false;
88
 
89
  AudioQueueStop(stateInp.queue, true);
@@ -98,7 +101,6 @@ void AudioInputCallback(void * inUserData,
98
  if (stateInp.isCapturing) {
99
  // stop capturing
100
  [self stopCapturing];
101
- [sender setTitle:@"Start Capturing" forState:UIControlStateNormal];
102
 
103
  return;
104
  }
@@ -127,6 +129,7 @@ void AudioInputCallback(void * inUserData,
127
  if (status == 0) {
128
  _labelStatusInp.text = @"Status: Capturing";
129
  [sender setTitle:@"Stop Capturing" forState:UIControlStateNormal];
 
130
  }
131
  }
132
 
@@ -141,7 +144,6 @@ void AudioInputCallback(void * inUserData,
141
  if (stateInp.isCapturing) {
142
  // stop capturing
143
  [self stopCapturing];
144
- [sender setTitle:@"Start Capturing" forState:UIControlStateNormal];
145
 
146
  return;
147
  }
@@ -168,6 +170,8 @@ void AudioInputCallback(void * inUserData,
168
  params.n_threads = 4;
169
  params.offset_ms = 0;
170
 
 
 
171
  if (whisper_full(stateInp.ctx, params, stateInp.audioBufferF32, stateInp.n_samples) != 0) {
172
  NSLog(@"Failed to run the model");
173
  _textviewResult.text = @"Failed to run the model";
@@ -175,6 +179,8 @@ void AudioInputCallback(void * inUserData,
175
  return;
176
  }
177
 
 
 
178
  // clear the text in the textview
179
  _textviewResult.text = @"";
180
 
@@ -186,7 +192,12 @@ void AudioInputCallback(void * inUserData,
186
  _textviewResult.text = [_textviewResult.text stringByAppendingString:[NSString stringWithUTF8String:text_cur]];
187
  }
188
 
 
189
  whisper_print_timings(stateInp.ctx);
 
 
 
 
190
  }
191
 
192
  //
 
84
 
85
  _labelStatusInp.text = @"Status: Idle";
86
 
87
+ [_buttonToggleCapture setTitle:@"Start capturing" forState:UIControlStateNormal];
88
+ [_buttonToggleCapture setBackgroundColor:[UIColor grayColor]];
89
+
90
  stateInp.isCapturing = false;
91
 
92
  AudioQueueStop(stateInp.queue, true);
 
101
  if (stateInp.isCapturing) {
102
  // stop capturing
103
  [self stopCapturing];
 
104
 
105
  return;
106
  }
 
129
  if (status == 0) {
130
  _labelStatusInp.text = @"Status: Capturing";
131
  [sender setTitle:@"Stop Capturing" forState:UIControlStateNormal];
132
+ [_buttonToggleCapture setBackgroundColor:[UIColor redColor]];
133
  }
134
  }
135
 
 
144
  if (stateInp.isCapturing) {
145
  // stop capturing
146
  [self stopCapturing];
 
147
 
148
  return;
149
  }
 
170
  params.n_threads = 4;
171
  params.offset_ms = 0;
172
 
173
+ CFTimeInterval startTime = CACurrentMediaTime();
174
+
175
  if (whisper_full(stateInp.ctx, params, stateInp.audioBufferF32, stateInp.n_samples) != 0) {
176
  NSLog(@"Failed to run the model");
177
  _textviewResult.text = @"Failed to run the model";
 
179
  return;
180
  }
181
 
182
+ CFTimeInterval endTime = CACurrentMediaTime();
183
+
184
  // clear the text in the textview
185
  _textviewResult.text = @"";
186
 
 
192
  _textviewResult.text = [_textviewResult.text stringByAppendingString:[NSString stringWithUTF8String:text_cur]];
193
  }
194
 
195
+ // internal model timing
196
  whisper_print_timings(stateInp.ctx);
197
+
198
+ NSLog(@"\nProcessing time: %5.3f", endTime - startTime);
199
+
200
+ _textviewResult.text = [_textviewResult.text stringByAppendingString:[NSString stringWithFormat:@"\n\n[processing time: %5.3f s]", endTime - startTime]];
201
  }
202
 
203
  //