diff --git a/android/src/main/java/com/rnwhisper/WhisperContext.java b/android/src/main/java/com/rnwhisper/WhisperContext.java index c0755fd..a8fe1c2 100644 --- a/android/src/main/java/com/rnwhisper/WhisperContext.java +++ b/android/src/main/java/com/rnwhisper/WhisperContext.java @@ -239,7 +239,19 @@ private void fullTranscribeSamples(ReadableMap options, boolean skipCapturingChe !isCapturing && nSamplesTranscribing == nSamplesOfIndex && sliceIndex == transcribeSliceIndex; - if (isStopped) { + + if ( + // If no more samples on current slice, move to next slice + nSamplesTranscribing == sliceNSamples.get(transcribeSliceIndex) && + transcribeSliceIndex != sliceIndex + ) { + transcribeSliceIndex++; + nSamplesTranscribing = 0; + } + + boolean continueNeeded = !isCapturing && nSamplesTranscribing != nSamplesOfIndex; + + if (isStopped && !continueNeeded) { payload.putBoolean("isCapturing", false); payload.putBoolean("isStoppedByAction", isStoppedByAction); emitTranscribeEvent("@RNWhisper_onRealtimeTranscribeEnd", payload); @@ -251,16 +263,7 @@ private void fullTranscribeSamples(ReadableMap options, boolean skipCapturingChe emitTranscribeEvent("@RNWhisper_onRealtimeTranscribe", payload); } - if ( - // If no more samples on current slice, move to next slice - nSamplesTranscribing == sliceNSamples.get(transcribeSliceIndex) && - transcribeSliceIndex != sliceIndex - ) { - transcribeSliceIndex++; - nSamplesTranscribing = 0; - } - - if (!isCapturing && nSamplesTranscribing != nSamplesOfIndex) { + if (continueNeeded) { // If no more capturing, continue transcribing until all slices are transcribed fullTranscribeSamples(options, true); } else if (isStopped) { @@ -368,7 +371,6 @@ public boolean isTranscribing() { public void stopTranscribe(int jobId) { abortTranscribe(jobId); isCapturing = false; - isTranscribing = false; isStoppedByAction = true; } diff --git a/example/ios/Podfile.lock b/example/ios/Podfile.lock index 9feff95..4bcddf8 100644 --- a/example/ios/Podfile.lock +++ b/example/ios/Podfile.lock @@ -416,7 +416,7 @@ PODS: - RNFS (2.20.0): - React-Core - SocketRocket (0.6.0) - - whisper-rn (0.3.0-rc.2): + - whisper-rn (0.3.0-rc.3): - React-Core - Yoga (1.14.0) - YogaKit (1.18.1): @@ -626,7 +626,7 @@ SPEC CHECKSUMS: ReactCommon: 85c98ab0a509e70bf5ee5d9715cf68dbf495b84c RNFS: 4ac0f0ea233904cb798630b3c077808c06931688 SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608 - whisper-rn: a05d78c47352e885c5d2cf89f095156e39ab837a + whisper-rn: 7b95b2e1bca9b3ddd7e8ffbc28ec75cd84c54a94 Yoga: 065f0b74dba4832d6e328238de46eb72c5de9556 YogaKit: f782866e155069a2cca2517aafea43200b01fd5a diff --git a/ios/RNWhisperContext.mm b/ios/RNWhisperContext.mm index 9f7f757..c11c267 100644 --- a/ios/RNWhisperContext.mm +++ b/ios/RNWhisperContext.mm @@ -180,14 +180,26 @@ - (void)fullTranscribeSamples:(RNWhisperContextRecordState*) state { } nSamplesOfIndex = [[state->sliceNSamples objectAtIndex:state->transcribeSliceIndex] intValue]; + + bool isStopped = state->isStoppedByAction || ( + !state->isCapturing && + state->nSamplesTranscribing == nSamplesOfIndex && + state->sliceIndex == state->transcribeSliceIndex + ); + if ( - state->isStoppedByAction || - ( - !state->isCapturing && - state->nSamplesTranscribing == nSamplesOfIndex && - state->sliceIndex == state->transcribeSliceIndex - ) + // If no more samples on current slice, move to next slice + state->nSamplesTranscribing == nSamplesOfIndex && + state->transcribeSliceIndex != state->sliceIndex ) { + state->transcribeSliceIndex++; + state->nSamplesTranscribing = 0; + } + + bool continueNeeded = !state->isCapturing && + state->nSamplesTranscribing != nSamplesOfIndex; + + if (isStopped && !continueNeeded) { NSLog(@"[RNWhisper] Transcribe end"); result[@"isStoppedByAction"] = @(state->isStoppedByAction); result[@"isCapturing"] = @(false); @@ -200,19 +212,7 @@ - (void)fullTranscribeSamples:(RNWhisperContextRecordState*) state { state->transcribeHandler(state->jobId, @"transcribe", result); } - if ( - // If no more samples on current slice, move to next slice - state->nSamplesTranscribing == nSamplesOfIndex && - state->transcribeSliceIndex != state->sliceIndex - ) { - state->transcribeSliceIndex++; - state->nSamplesTranscribing = 0; - } - - if ( - !state->isCapturing && - state->nSamplesTranscribing != nSamplesOfIndex - ) { + if (continueNeeded) { state->isTranscribing = true; // Finish transcribing the rest of the samples [self fullTranscribeSamples:state]; @@ -285,7 +285,6 @@ - (void)stopTranscribe:(int)jobId { if (!self->recordState.isRealtime || !self->recordState.isCapturing) { return; } - self->recordState.isTranscribing = false; self->recordState.isCapturing = false; self->recordState.isStoppedByAction = true; [self stopAudio];