]> git.djapps.eu Git - pkg/ggml/sources/whisper.cpp/commitdiff
objc : polishing the sample application
authorGeorgi Gerganov <redacted>
Sun, 23 Oct 2022 09:24:03 +0000 (12:24 +0300)
committerGeorgi Gerganov <redacted>
Mon, 24 Oct 2022 15:23:07 +0000 (18:23 +0300)
examples/whisper.objc/whisper.objc/Base.lproj/Main.storyboard
examples/whisper.objc/whisper.objc/ViewController.m

index 0079b25e1fcbbf1714b4b8cec5d5cd9927b66727..5c92ba8b09f8927a3bc55fa4327c197e244b02e4 100644 (file)
@@ -17,7 +17,7 @@
                         <autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMinY="YES" heightSizable="YES"/>
                         <subviews>
                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="VOi-PT-Rbu">
-                                <rect key="frame" x="35" y="121" width="156" height="34"/>
+                                <rect key="frame" x="35" y="121" width="156" height="49"/>
                                 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                 <color key="backgroundColor" systemColor="opaqueSeparatorColor"/>
                                 <color key="tintColor" systemColor="opaqueSeparatorColor"/>
                                 <nil key="textColor"/>
                                 <nil key="highlightedColor"/>
                             </label>
+                            <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">
+                                <rect key="frame" x="35" y="248" width="320" height="300"/>
+                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
+                                <color key="backgroundColor" systemColor="systemBackgroundColor"/>
+                                <color key="textColor" systemColor="labelColor"/>
+                                <fontDescription key="fontDescription" type="system" pointSize="20"/>
+                                <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
+                            </textView>
                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="Brs-xi-o8i">
-                                <rect key="frame" x="35" y="177" width="156" height="34"/>
+                                <rect key="frame" x="35" y="191" width="156" height="49"/>
                                 <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                 <color key="backgroundColor" systemColor="opaqueSeparatorColor"/>
                                 <color key="tintColor" systemColor="opaqueSeparatorColor"/>
                                     <action selector="onTranscribePrepare:" destination="BYZ-38-t0r" eventType="touchDown" id="16T-dN-dfB"/>
                                 </connections>
                             </button>
-                            <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">
-                                <rect key="frame" x="35" y="248" width="320" height="300"/>
-                                <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
-                                <color key="backgroundColor" systemColor="systemBackgroundColor"/>
-                                <color key="textColor" systemColor="labelColor"/>
-                                <fontDescription key="fontDescription" type="system" pointSize="14"/>
-                                <textInputTraits key="textInputTraits" autocapitalizationType="sentences"/>
-                            </textView>
                         </subviews>
                         <viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
                         <color key="backgroundColor" systemColor="systemBackgroundColor"/>
@@ -64,6 +64,7 @@
                         </constraints>
                     </view>
                     <connections>
+                        <outlet property="buttonToggleCapture" destination="VOi-PT-Rbu" id="nis-VC-DQO"/>
                         <outlet property="buttonTranscribe" destination="Brs-xi-o8i" id="N8h-9W-ywb"/>
                         <outlet property="labelStatusInp" destination="Tgu-2q-eHQ" id="1hH-Ql-K6j"/>
                         <outlet property="textviewResult" destination="mv2-KD-7jn" id="RBw-0L-iGj"/>
index 6d3219bfd37b9fc8001c9a95c93c1cb348cfccdd..07feb5545ef3bef469dffdd39970aa2f1ac7037e 100644 (file)
@@ -84,6 +84,9 @@ void AudioInputCallback(void * inUserData,
 
     _labelStatusInp.text = @"Status: Idle";
 
+    [_buttonToggleCapture setTitle:@"Start capturing" forState:UIControlStateNormal];
+    [_buttonToggleCapture setBackgroundColor:[UIColor grayColor]];
+
     stateInp.isCapturing = false;
 
     AudioQueueStop(stateInp.queue, true);
@@ -98,7 +101,6 @@ void AudioInputCallback(void * inUserData,
     if (stateInp.isCapturing) {
         // stop capturing
         [self stopCapturing];
-        [sender setTitle:@"Start Capturing" forState:UIControlStateNormal];
 
         return;
     }
@@ -127,6 +129,7 @@ void AudioInputCallback(void * inUserData,
         if (status == 0) {
             _labelStatusInp.text = @"Status: Capturing";
             [sender setTitle:@"Stop Capturing" forState:UIControlStateNormal];
+            [_buttonToggleCapture setBackgroundColor:[UIColor redColor]];
         }
     }
 
@@ -141,7 +144,6 @@ void AudioInputCallback(void * inUserData,
     if (stateInp.isCapturing) {
         // stop capturing
         [self stopCapturing];
-        [sender setTitle:@"Start Capturing" forState:UIControlStateNormal];
 
         return;
     }
@@ -168,6 +170,8 @@ void AudioInputCallback(void * inUserData,
     params.n_threads            = 4;
     params.offset_ms            = 0;
 
+    CFTimeInterval startTime = CACurrentMediaTime();
+
     if (whisper_full(stateInp.ctx, params, stateInp.audioBufferF32, stateInp.n_samples) != 0) {
         NSLog(@"Failed to run the model");
         _textviewResult.text = @"Failed to run the model";
@@ -175,6 +179,8 @@ void AudioInputCallback(void * inUserData,
         return;
     }
 
+    CFTimeInterval endTime = CACurrentMediaTime();
+
     // clear the text in the textview
     _textviewResult.text = @"";
 
@@ -186,7 +192,12 @@ void AudioInputCallback(void * inUserData,
         _textviewResult.text = [_textviewResult.text stringByAppendingString:[NSString stringWithUTF8String:text_cur]];
     }
 
+    // internal model timing
     whisper_print_timings(stateInp.ctx);
+
+    NSLog(@"\nProcessing time: %5.3f", endTime - startTime);
+
+    _textviewResult.text = [_textviewResult.text stringByAppendingString:[NSString stringWithFormat:@"\n\n[processing time: %5.3f s]", endTime - startTime]];
 }
 
 //