dsh-tinyasr 1.10.0 → 1.10.2

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.
Files changed (3) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/client.js +40 -16
  3. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,19 @@
3
3
  All notable changes to this plugin. Entries up to 1.11.0 are local pre-release iterations of the
4
4
  1.0 line; the public package starts at 1.2.0.
5
5
 
6
+ ## 1.10.2 — 7 December 2026
7
+
8
+ - Recovery housekeeping: the tap buffer stops growing at 310 s, an unclaimed transcript expires after
9
+ 10 minutes, discards are logged (`tap discard`), and `tap`/`recover` lines carry the session tail so
10
+ a recovery can be traced to its conversation.
11
+
12
+ ## 1.10.1 — 7 December 2026
13
+
14
+ - The recovery keeps the conversation captured when the recording started instead of reading it
15
+ when the recorder cancels — by then the DOM already belongs to the conversation the user switched
16
+ to, which is why the text was inserted into the wrong chat. A `waiting` log line shows when the
17
+ text waits for its own conversation.
18
+
6
19
  ## 1.10.0 — 7 December 2026
7
20
 
8
21
  - Switching chats (or leaving the conversation) while dictating no longer loses the take. The
package/client.js CHANGED
@@ -800,6 +800,7 @@ window.__ModuleLoader__.load({
800
800
  // conversation. Returning to that conversation inserts the text into the draft.
801
801
  let tap = null
802
802
  const pendingRecovery = new Map()
803
+ const PENDING_TTL_MS = 10 * 60 * 1000
803
804
  const sessionOf = () => {
804
805
  const node = document.querySelector('[data-conversation-session]')
805
806
  const value = node?.getAttribute('data-conversation-session')
@@ -830,8 +831,11 @@ window.__ModuleLoader__.load({
830
831
  await audio.resume()
831
832
  const source = audio.createMediaStreamSource(media)
832
833
  const processor = audio.createScriptProcessor(2048, 1, 1)
833
- const state = { media, audio, source, processor, chunks: [], length: 0 }
834
+ // The session must be read now: by the time the recorder cancels, the URL and the DOM
835
+ // already belong to the conversation the user switched to.
836
+ const state = { media, audio, source, processor, chunks: [], length: 0, session: sessionOf() }
834
837
  processor.onaudioprocess = (event) => {
838
+ if (state.length >= 16000 * 310) return // the recorder caps at 300 s; never grow past it
835
839
  const block = event.inputBuffer.getChannelData(0)
836
840
  const samples = audio.sampleRate === 16000 ? block : resample(block, audio.sampleRate)
837
841
  const copy = new Float32Array(samples.length)
@@ -842,7 +846,7 @@ window.__ModuleLoader__.load({
842
846
  source.connect(processor)
843
847
  processor.connect(audio.destination)
844
848
  tap = state
845
- hello('tap', { stage: 'start' })
849
+ hello('tap', { stage: 'start', session: state.session.slice(-8) })
846
850
  } catch (error) {
847
851
  hello('tap', { stage: 'failed', message: String(error?.message ?? error).slice(0, 120) })
848
852
  }
@@ -855,40 +859,59 @@ window.__ModuleLoader__.load({
855
859
  try { state.source.disconnect() } catch {}
856
860
  try { for (const track of state.media.getTracks()) track.stop() } catch {}
857
861
  try { await state.audio.close() } catch {}
858
- if (!keep) return null
862
+ if (!keep) { hello('tap', { stage: 'discard', ms: String(state.length * 1000 / 16000 | 0) }); return null }
859
863
  const wav = encodeWav(state.chunks, state.length, 16000)
860
- if (wav.length <= 44) return ''
864
+ if (wav.length <= 44) return { text: '', session: state.session }
861
865
  try {
862
866
  const response = await fetch('/api/tinyasr/transcribe', {
863
867
  method: 'POST', credentials: 'same-origin', headers: WRITE,
864
868
  body: JSON.stringify({ audio: toBase64(wav), language: 'auto' }),
865
869
  })
866
870
  const body = await response.json().catch(() => ({}))
867
- return typeof body.text === 'string' ? body.text : ''
871
+ return { text: typeof body.text === 'string' ? body.text : '', session: state.session }
868
872
  } catch (error) {
869
873
  hello('recover', { stage: 'failed', message: String(error?.message ?? error).slice(0, 120) })
870
- return ''
874
+ return { text: '', session: state.session }
871
875
  }
872
876
  }
877
+ const waitingLogged = new Set()
873
878
  const flushRecovery = () => {
879
+ if (pendingRecovery.size === 0) return
880
+ const now = Date.now()
881
+ for (const [key, entry] of pendingRecovery) {
882
+ if (now - entry.at > PENDING_TTL_MS) { pendingRecovery.delete(key); hello('recover', { stage: 'expired', session: key.slice(-8) }) }
883
+ }
874
884
  if (pendingRecovery.size === 0) return
875
885
  if (tap !== null) return
876
886
  const session = sessionOf()
877
- if (session === '' || !pendingRecovery.has(session)) return
887
+ if (session === '' || !pendingRecovery.has(session)) {
888
+ // The text waits for its own conversation: log the mismatch once per session.
889
+ for (const key of pendingRecovery.keys()) {
890
+ if (key !== session && !waitingLogged.has(key)) {
891
+ waitingLogged.add(key)
892
+ hello('recover', { stage: 'waiting', for: key.slice(-8), session: session.slice(-8) })
893
+ }
894
+ }
895
+ return
896
+ }
897
+ waitingLogged.delete(session)
878
898
  if (document.querySelector('[data-voice-activity]') !== null) return
879
- const text = pendingRecovery.get(session)
880
- if (insertIntoComposer(text)) {
899
+ const entry = pendingRecovery.get(session)
900
+ if (insertIntoComposer(entry.text)) {
881
901
  pendingRecovery.delete(session)
882
- hello('recover', { stage: 'inserted', chars: String(text.length) })
902
+ hello('recover', { stage: 'inserted', chars: String(entry.text.length), session: session.slice(-8) })
883
903
  }
884
904
  }
885
905
  const recoverCancelledTake = async () => {
886
- const text = await stopTap(true)
887
- if (typeof text !== 'string' || text.trim() === '') return
888
- const session = sessionOf()
889
- if (session === '') return
890
- pendingRecovery.set(session, text.trim())
891
- hello('recover', { stage: 'stashed', chars: String(text.trim().length) })
906
+ const result = await stopTap(true)
907
+ if (result === null) return
908
+ const text = result.text.trim()
909
+ if (text === '') return
910
+ const session = result.session
911
+ if (session === '') { hello('recover', { stage: 'no-session', chars: String(text.length) }); return }
912
+ const previous = pendingRecovery.get(session)
913
+ pendingRecovery.set(session, { text: previous === undefined ? text : `${previous.text} ${text}`, at: Date.now() })
914
+ hello('recover', { stage: 'stashed', chars: String(text.length), session: session.slice(-8) })
892
915
  }
893
916
 
894
917
  // Track the built-in recorder's phase so a dropped recording leaves evidence on the Host.
@@ -903,6 +926,7 @@ window.__ModuleLoader__.load({
903
926
  if (phase === 'recording') { recordingAt = Date.now(); void startTap() }
904
927
  hello('voice', { phase, message: (row?.textContent ?? '').slice(0, 140) })
905
928
  if (phase === 'transcribing') void stopTap(false)
929
+ if (tap !== null && phase !== 'recording' && !(previous === 'recording' && phase === 'idle')) void stopTap(false)
906
930
  // recording → idle without transcribing means the recorder was cancelled (chat switch,
907
931
  // window blur, Escape). The parallel tap turns that into a transcript for the draft.
908
932
  if (previous === 'recording' && phase === 'idle' && recordingAt > 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-tinyasr",
3
- "version": "1.10.0",
3
+ "version": "1.10.2",
4
4
  "type": "module",
5
5
  "main": "./index.js",
6
6
  "description": "Offline Russian and English dictation for the DeepSeek Harness Web GUI through the local tinyasr recognizer, with an optional model cleanup pass.",