forked from extern/whisper.cpp
objc : polishing the sample application
This commit is contained in:
parent
b41f4a90eb
commit
a52ee08c1e
@ -17,7 +17,7 @@
|
|||||||
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMinY="YES" heightSizable="YES"/>
|
<autoresizingMask key="autoresizingMask" flexibleMinX="YES" widthSizable="YES" flexibleMinY="YES" heightSizable="YES"/>
|
||||||
<subviews>
|
<subviews>
|
||||||
<button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" id="VOi-PT-Rbu">
|
<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"/>
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||||
<color key="backgroundColor" systemColor="opaqueSeparatorColor"/>
|
<color key="backgroundColor" systemColor="opaqueSeparatorColor"/>
|
||||||
<color key="tintColor" systemColor="opaqueSeparatorColor"/>
|
<color key="tintColor" systemColor="opaqueSeparatorColor"/>
|
||||||
@ -35,8 +35,16 @@
|
|||||||
<nil key="textColor"/>
|
<nil key="textColor"/>
|
||||||
<nil key="highlightedColor"/>
|
<nil key="highlightedColor"/>
|
||||||
</label>
|
</label>
|
||||||
|
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" text="Record some speech and press "Transcribe". 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">
|
<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"/>
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
|
||||||
<color key="backgroundColor" systemColor="opaqueSeparatorColor"/>
|
<color key="backgroundColor" systemColor="opaqueSeparatorColor"/>
|
||||||
<color key="tintColor" systemColor="opaqueSeparatorColor"/>
|
<color key="tintColor" systemColor="opaqueSeparatorColor"/>
|
||||||
@ -48,14 +56,6 @@
|
|||||||
<action selector="onTranscribePrepare:" destination="BYZ-38-t0r" eventType="touchDown" id="16T-dN-dfB"/>
|
<action selector="onTranscribePrepare:" destination="BYZ-38-t0r" eventType="touchDown" id="16T-dN-dfB"/>
|
||||||
</connections>
|
</connections>
|
||||||
</button>
|
</button>
|
||||||
<textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" fixedFrame="YES" text="Record some speech and press "Transcribe". 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>
|
</subviews>
|
||||||
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
|
<viewLayoutGuide key="safeArea" id="6Tk-OE-BBY"/>
|
||||||
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
|
||||||
@ -64,6 +64,7 @@
|
|||||||
</constraints>
|
</constraints>
|
||||||
</view>
|
</view>
|
||||||
<connections>
|
<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="buttonTranscribe" destination="Brs-xi-o8i" id="N8h-9W-ywb"/>
|
||||||
<outlet property="labelStatusInp" destination="Tgu-2q-eHQ" id="1hH-Ql-K6j"/>
|
<outlet property="labelStatusInp" destination="Tgu-2q-eHQ" id="1hH-Ql-K6j"/>
|
||||||
<outlet property="textviewResult" destination="mv2-KD-7jn" id="RBw-0L-iGj"/>
|
<outlet property="textviewResult" destination="mv2-KD-7jn" id="RBw-0L-iGj"/>
|
||||||
|
@ -84,6 +84,9 @@ void AudioInputCallback(void * inUserData,
|
|||||||
|
|
||||||
_labelStatusInp.text = @"Status: Idle";
|
_labelStatusInp.text = @"Status: Idle";
|
||||||
|
|
||||||
|
[_buttonToggleCapture setTitle:@"Start capturing" forState:UIControlStateNormal];
|
||||||
|
[_buttonToggleCapture setBackgroundColor:[UIColor grayColor]];
|
||||||
|
|
||||||
stateInp.isCapturing = false;
|
stateInp.isCapturing = false;
|
||||||
|
|
||||||
AudioQueueStop(stateInp.queue, true);
|
AudioQueueStop(stateInp.queue, true);
|
||||||
@ -98,7 +101,6 @@ void AudioInputCallback(void * inUserData,
|
|||||||
if (stateInp.isCapturing) {
|
if (stateInp.isCapturing) {
|
||||||
// stop capturing
|
// stop capturing
|
||||||
[self stopCapturing];
|
[self stopCapturing];
|
||||||
[sender setTitle:@"Start Capturing" forState:UIControlStateNormal];
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -127,6 +129,7 @@ void AudioInputCallback(void * inUserData,
|
|||||||
if (status == 0) {
|
if (status == 0) {
|
||||||
_labelStatusInp.text = @"Status: Capturing";
|
_labelStatusInp.text = @"Status: Capturing";
|
||||||
[sender setTitle:@"Stop Capturing" forState:UIControlStateNormal];
|
[sender setTitle:@"Stop Capturing" forState:UIControlStateNormal];
|
||||||
|
[_buttonToggleCapture setBackgroundColor:[UIColor redColor]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,7 +144,6 @@ void AudioInputCallback(void * inUserData,
|
|||||||
if (stateInp.isCapturing) {
|
if (stateInp.isCapturing) {
|
||||||
// stop capturing
|
// stop capturing
|
||||||
[self stopCapturing];
|
[self stopCapturing];
|
||||||
[sender setTitle:@"Start Capturing" forState:UIControlStateNormal];
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -168,6 +170,8 @@ void AudioInputCallback(void * inUserData,
|
|||||||
params.n_threads = 4;
|
params.n_threads = 4;
|
||||||
params.offset_ms = 0;
|
params.offset_ms = 0;
|
||||||
|
|
||||||
|
CFTimeInterval startTime = CACurrentMediaTime();
|
||||||
|
|
||||||
if (whisper_full(stateInp.ctx, params, stateInp.audioBufferF32, stateInp.n_samples) != 0) {
|
if (whisper_full(stateInp.ctx, params, stateInp.audioBufferF32, stateInp.n_samples) != 0) {
|
||||||
NSLog(@"Failed to run the model");
|
NSLog(@"Failed to run the model");
|
||||||
_textviewResult.text = @"Failed to run the model";
|
_textviewResult.text = @"Failed to run the model";
|
||||||
@ -175,6 +179,8 @@ void AudioInputCallback(void * inUserData,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CFTimeInterval endTime = CACurrentMediaTime();
|
||||||
|
|
||||||
// clear the text in the textview
|
// clear the text in the textview
|
||||||
_textviewResult.text = @"";
|
_textviewResult.text = @"";
|
||||||
|
|
||||||
@ -186,7 +192,12 @@ void AudioInputCallback(void * inUserData,
|
|||||||
_textviewResult.text = [_textviewResult.text stringByAppendingString:[NSString stringWithUTF8String:text_cur]];
|
_textviewResult.text = [_textviewResult.text stringByAppendingString:[NSString stringWithUTF8String:text_cur]];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// internal model timing
|
||||||
whisper_print_timings(stateInp.ctx);
|
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]];
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user