whisper.rn 0.3.1 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -71,7 +71,7 @@ public class WhisperContext {
71
71
  bufferSize = AudioRecord.getMinBufferSize(SAMPLE_RATE, CHANNEL_CONFIG, AUDIO_FORMAT);
72
72
  }
73
73
 
74
- private void resetRealtimeTranscribe() {
74
+ private void rewind() {
75
75
  shortBufferSlices = null;
76
76
  sliceNSamples = null;
77
77
  sliceIndex = 0;
@@ -97,7 +97,7 @@ public class WhisperContext {
97
97
  return state;
98
98
  }
99
99
 
100
- resetRealtimeTranscribe();
100
+ rewind();
101
101
 
102
102
  this.jobId = jobId;
103
103
 
@@ -269,7 +269,7 @@ public class WhisperContext {
269
269
  fullTranscribeSamples(options, true);
270
270
  } else if (isStopped) {
271
271
  // No next, cleanup
272
- resetRealtimeTranscribe();
272
+ rewind();
273
273
  }
274
274
  isTranscribing = false;
275
275
  }
@@ -303,6 +303,11 @@ public class WhisperContext {
303
303
  }
304
304
 
305
305
  public WritableMap transcribeInputStream(int jobId, InputStream inputStream, ReadableMap options) throws IOException, Exception {
306
+ if (isCapturing || isTranscribing) {
307
+ throw new Exception("Context is already in capturing or transcribing");
308
+ }
309
+ rewind();
310
+
306
311
  this.jobId = jobId;
307
312
  isTranscribing = true;
308
313
  float[] audioData = decodeWaveFile(inputStream);
@@ -312,7 +317,9 @@ public class WhisperContext {
312
317
  if (code != 0) {
313
318
  throw new Exception("Failed to transcribe the file. Code: " + code);
314
319
  }
315
- return getTextSegments();
320
+ WritableMap result = getTextSegments();
321
+ result.putBoolean("isAborted", isStoppedByAction);
322
+ return result;
316
323
  }
317
324
 
318
325
  private int full(int jobId, ReadableMap options, float[] audioData, int audioDataLen) {