@speakableio/core 1.0.64 → 1.0.65

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.
@@ -1699,6 +1699,7 @@ declare function getTranscriptCycle(args: {
1699
1699
  audioUrl: string;
1700
1700
  language: string;
1701
1701
  prompt?: string;
1702
+ cleanHallucinations?: boolean;
1702
1703
  }): Promise<{
1703
1704
  transcript: string;
1704
1705
  success: boolean;
@@ -2971,6 +2972,7 @@ declare function useSpeakableTranscript(): {
2971
2972
  audioUrl: string;
2972
2973
  language: string;
2973
2974
  prompt?: string;
2975
+ cleanHallucinations?: boolean;
2974
2976
  }, unknown>;
2975
2977
  };
2976
2978
  declare function useSpeakableTranscriptCycle(): {
@@ -2981,6 +2983,7 @@ declare function useSpeakableTranscriptCycle(): {
2981
2983
  audioUrl: string;
2982
2984
  language: string;
2983
2985
  prompt: string;
2986
+ cleanHallucinations?: boolean;
2984
2987
  }, unknown>;
2985
2988
  };
2986
2989
 
@@ -1699,6 +1699,7 @@ declare function getTranscriptCycle(args: {
1699
1699
  audioUrl: string;
1700
1700
  language: string;
1701
1701
  prompt?: string;
1702
+ cleanHallucinations?: boolean;
1702
1703
  }): Promise<{
1703
1704
  transcript: string;
1704
1705
  success: boolean;
@@ -2971,6 +2972,7 @@ declare function useSpeakableTranscript(): {
2971
2972
  audioUrl: string;
2972
2973
  language: string;
2973
2974
  prompt?: string;
2975
+ cleanHallucinations?: boolean;
2974
2976
  }, unknown>;
2975
2977
  };
2976
2978
  declare function useSpeakableTranscriptCycle(): {
@@ -2981,6 +2983,7 @@ declare function useSpeakableTranscriptCycle(): {
2981
2983
  audioUrl: string;
2982
2984
  language: string;
2983
2985
  prompt: string;
2986
+ cleanHallucinations?: boolean;
2984
2987
  }, unknown>;
2985
2988
  };
2986
2989
 
@@ -2333,6 +2333,10 @@ function detectTranscriptHallucination(transcript) {
2333
2333
  return false;
2334
2334
  }
2335
2335
  const text = transcript.trim();
2336
+ const wordCount = text.split(/\s+/).filter(Boolean).length;
2337
+ if (text.length < 120 || wordCount < 20) {
2338
+ return false;
2339
+ }
2336
2340
  const shortRepeats = detectShortRepeats(text);
2337
2341
  if (shortRepeats) return true;
2338
2342
  const phraseRepeats = detectPhraseRepeats(text);
@@ -2348,14 +2352,14 @@ function detectShortRepeats(text) {
2348
2352
  for (let i = 1; i < words.length; i++) {
2349
2353
  if (words[i] === words[i - 1]) {
2350
2354
  repeatCount++;
2351
- if (repeatCount >= 3) return true;
2355
+ if (repeatCount >= 4) return true;
2352
2356
  } else {
2353
2357
  repeatCount = 1;
2354
2358
  }
2355
2359
  }
2356
2360
  const uniqueWords = new Set(words);
2357
2361
  const repetitionRatio = words.length / uniqueWords.size;
2358
- if (words.length >= 10 && uniqueWords.size <= 3 && repetitionRatio >= 3) {
2362
+ if (words.length >= 12 && uniqueWords.size <= 2 && repetitionRatio >= 5) {
2359
2363
  return true;
2360
2364
  }
2361
2365
  return false;
@@ -2372,12 +2376,12 @@ function detectPhraseRepeats(text) {
2372
2376
  break;
2373
2377
  }
2374
2378
  }
2375
- if (consecutiveRepeats >= 2) {
2379
+ if (consecutiveRepeats >= 3) {
2376
2380
  return true;
2377
2381
  }
2378
2382
  }
2379
2383
  const uniqueSentences = new Set(sentences);
2380
- if (sentences.length >= 3 && uniqueSentences.size === 1) {
2384
+ if (sentences.length >= 4 && uniqueSentences.size === 1) {
2381
2385
  return true;
2382
2386
  }
2383
2387
  return false;
@@ -2394,7 +2398,7 @@ function isSimilarSentence(s1, s2) {
2394
2398
  const set2 = new Set(words2);
2395
2399
  const intersection = new Set([...set1].filter((w) => set2.has(w)));
2396
2400
  const similarity = intersection.size * 2 / (set1.size + set2.size);
2397
- return similarity >= 0.8;
2401
+ return similarity >= 0.9;
2398
2402
  }
2399
2403
  function detectCyclicPattern(text) {
2400
2404
  const normalized = text.toLowerCase().replace(/\s+/g, " ").trim();
@@ -2414,7 +2418,7 @@ function detectCyclicPattern(text) {
2414
2418
  break;
2415
2419
  }
2416
2420
  }
2417
- if (matchCount >= 3) {
2421
+ if (matchCount >= 4) {
2418
2422
  return true;
2419
2423
  }
2420
2424
  }
@@ -2435,7 +2439,7 @@ async function getTranscript(model, args, cleanHallucinations = true) {
2435
2439
  const getAssemblyAITranscript = (_d = (_c = api).httpsCallable) == null ? void 0 : _d.call(_c, "transcribeAssemblyAIAudio");
2436
2440
  const getWhisper3Transcript = (_f = (_e = api).httpsCallable) == null ? void 0 : _f.call(_e, "generateGroqTranscript");
2437
2441
  const getWhisper1Transcript = (_h = (_g = api).httpsCallable) == null ? void 0 : _h.call(_g, "transcribeAudio");
2438
- console.log("Getting transcript from", model);
2442
+ console.log("Getting transcript from", model, " cleanHallucinations", cleanHallucinations);
2439
2443
  if (model === "whisper-3") {
2440
2444
  try {
2441
2445
  const { data } = await (getWhisper3Transcript == null ? void 0 : getWhisper3Transcript({
@@ -2488,13 +2492,19 @@ async function getTranscript(model, args, cleanHallucinations = true) {
2488
2492
  return null;
2489
2493
  }
2490
2494
  async function getTranscriptCycle(args) {
2495
+ var _a;
2491
2496
  const models = ["whisper-3", "whisper", "gemini", "assemblyai"];
2492
2497
  let transcript = "";
2493
2498
  let lastError = null;
2494
2499
  for (const model of models) {
2495
2500
  try {
2496
- console.log("Getting transcript from", model);
2497
- const transcriptResult = await getTranscript(model, args, false);
2501
+ console.log(
2502
+ "Getting transcript from",
2503
+ model,
2504
+ " cleanHallucinations",
2505
+ args.cleanHallucinations
2506
+ );
2507
+ const transcriptResult = await getTranscript(model, args, (_a = args.cleanHallucinations) != null ? _a : true);
2498
2508
  const rawTranscript = transcriptResult || "";
2499
2509
  transcript = cleanHallucinatedTranscript(rawTranscript);
2500
2510
  if (transcript !== "") {
@@ -3253,9 +3263,10 @@ function useSpeakableTranscript() {
3253
3263
  model,
3254
3264
  audioUrl,
3255
3265
  language,
3256
- prompt
3266
+ prompt,
3267
+ cleanHallucinations = true
3257
3268
  }) => {
3258
- return getTranscript(model, { audioUrl, language, prompt });
3269
+ return getTranscript(model, { audioUrl, language, prompt }, cleanHallucinations);
3259
3270
  },
3260
3271
  retry: false
3261
3272
  });
@@ -3266,7 +3277,7 @@ function useSpeakableTranscript() {
3266
3277
  function useSpeakableTranscriptCycle() {
3267
3278
  const mutation = (0, import_react_query7.useMutation)({
3268
3279
  mutationFn: async (args) => {
3269
- return getTranscriptCycle(args);
3280
+ return getTranscriptCycle({ ...args, cleanHallucinations: args.cleanHallucinations });
3270
3281
  },
3271
3282
  retry: false
3272
3283
  });