Skip to content

armgit / clipy

Public Imported from GitHub
0

The AI-native screen recorder. Record your screen and talk; the people you share it with and your AI agents both get it.

Sync from upstream d6a77379cfea

github-actions[bot]c17dd8ddd707
diff --git a/desktop/src-tauri/src/dictation.rs b/desktop/src-tauri/src/dictation.rs
index b149875..e8dae67 100644
--- a/desktop/src-tauri/src/dictation.rs
+++ b/desktop/src-tauri/src/dictation.rs
@@ -152,22 +152,27 @@ impl Pcm16k {
}
/// Transcribes a dictation while the key is still held. Each time the
-/// speaker pauses after at least `MIN_PIECE_SEC` of new audio, the audio up
-/// to that pause goes to the chosen model on a background thread, so the
-/// release only waits for the words after the last pause. Cuts fall inside
-/// a pause, so no word is split.
+/// speaker pauses for `CUT_PAUSE_SEC` after at least `MIN_PIECE_SEC` of new
+/// audio, the audio up to that pause goes to the chosen model on a
+/// background thread, so the release only waits for the words after the
+/// last pause. Cuts fall inside a pause, so no word is split.
#[cfg(any(target_os = "macos", target_os = "windows"))]
#[cfg_attr(target_os = "macos", allow(dead_code))]
pub(crate) mod ahead {
use super::PCM_RATE;
use crate::transcription_models::{self, ChosenModel};
- use clipy_local_stt::audio::{detect_silences, SILENCE_MIN_SEC, SILENCE_NOISE_DB};
+ use clipy_local_stt::audio::{detect_silences, SILENCE_NOISE_DB};
use clipy_local_stt::{Gap, Segment, Transcript};
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{mpsc, Arc};
use std::thread::JoinHandle;
const MIN_PIECE_SEC: usize = 5;
+ /// The shortest pause cut at. The model ends every piece as a sentence
+ /// (a full stop, the next piece capitalized), so a cut at a breath in
+ /// mid-sentence shows up in the text. A pause this long is usually
+ /// between sentences; shorter ones (`SILENCE_MIN_SEC`) often are not.
+ const CUT_PAUSE_SEC: f64 = 0.8;
/// How much new audio between looks for a pause.
const LOOK_EVERY: usize = PCM_RATE as usize / 4;
/// Where in a pause the cut goes, at most this far past its start.
@@ -278,14 +283,15 @@ pub(crate) mod ahead {
}
/// Where to cut `fresh` (audio not yet handed over): inside the latest
- /// pause that starts at least `MIN_PIECE_SEC` in.
+ /// pause of `CUT_PAUSE_SEC` or more that starts at least `MIN_PIECE_SEC`
+ /// in.
pub(crate) fn next_cut(fresh: &[f32]) -> Option<usize> {
let min = MIN_PIECE_SEC * PCM_RATE as usize;
if fresh.len() < min {
return None;
}
let rate = f64::from(PCM_RATE);
- detect_silences(fresh, SILENCE_NOISE_DB, SILENCE_MIN_SEC)
+ detect_silences(fresh, SILENCE_NOISE_DB, CUT_PAUSE_SEC)
.iter()
.rev()
.map(|pause| {
@@ -357,16 +363,18 @@ pub(crate) mod ahead {
}
#[test]
- fn cuts_inside_the_first_pause_after_five_seconds_only() {
+ fn cuts_inside_a_long_pause_after_five_seconds_only() {
let rate = PCM_RATE as usize;
assert_eq!(next_cut(&audio(&[(4.0, true)])), None);
// A pause at 2 s is too early; speech with no pause gives no cut.
- assert_eq!(next_cut(&audio(&[(2.0, true), (0.6, false), (4.0, true)])), None);
+ assert_eq!(next_cut(&audio(&[(2.0, true), (1.0, false), (4.0, true)])), None);
assert_eq!(next_cut(&audio(&[(7.0, true)])), None);
- let cut = next_cut(&audio(&[(6.0, true), (0.6, false), (1.0, true)])).unwrap();
+ // A short breath, as in mid-sentence, is not cut at.
+ assert_eq!(next_cut(&audio(&[(6.0, true), (0.5, false), (1.0, true)])), None);
+ let cut = next_cut(&audio(&[(6.0, true), (1.0, false), (1.0, true)])).unwrap();
assert!(cut > 6 * rate && cut < 6 * rate + rate * 6 / 10, "{cut}");
// A pause still running at the end is cut into, too.
- let cut = next_cut(&audio(&[(6.0, true), (0.5, false)])).unwrap();
+ let cut = next_cut(&audio(&[(6.0, true), (0.9, false)])).unwrap();
assert!(cut > 6 * rate && cut <= 6 * rate + rate / 2, "{cut}");
}
diff --git a/desktop/src-tauri/src/transcription_models.rs b/desktop/src-tauri/src/transcription_models.rs
index 8eb4a9b..053c142 100644
--- a/desktop/src-tauri/src/transcription_models.rs
+++ b/desktop/src-tauri/src/transcription_models.rs
@@ -622,16 +622,6 @@ mod imp {
Ok(())
}
- /// Transcribes 16 kHz mono samples with `model`. Blocking; call it from
- /// the processing thread. `words` are the take's dictionary words
- /// (`transcription_dictionary::prompt_words`): `english-words` gets them
- /// as hotwords, Parakeet English on the Neural Engine as vocabulary
- /// boosting terms (with the saved "sounds like" spellings as aliases,
- /// `transcription_dictionary::boost_terms`), the others ignore them, and
- /// every model's transcript still gets the spelling pass afterwards.
- /// When the engine was given the words, a word it repeats three or more
- /// times in a row is collapsed to one first (boosting can write a listed
- /// word over and over where nothing was said).
/// Starts loading `model` so the transcription that follows (a dictation
/// being spoken now) skips the load. Returns at once. The Neural Engine
/// models keep themselves loaded.
@@ -643,6 +633,16 @@ mod imp {
}
}
+ /// Transcribes 16 kHz mono samples with `model`. Blocking; call it from
+ /// the processing thread. `words` are the take's dictionary words
+ /// (`transcription_dictionary::prompt_words`): `english-words` gets them
+ /// as hotwords, Parakeet English on the Neural Engine as vocabulary
+ /// boosting terms (with the saved "sounds like" spellings as aliases,
+ /// `transcription_dictionary::boost_terms`), the others ignore them, and
+ /// every model's transcript still gets the spelling pass afterwards.
+ /// When the engine was given the words, a word it repeats three or more
+ /// times in a row is collapsed to one first (boosting can write a listed
+ /// word over and over where nothing was said).
pub(crate) fn transcribe(
model: ChosenModel,
pcm: &[f32],