@goodandready/dsh-voice 0.9.4 → 0.9.6

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.
package/lib/client.js CHANGED
@@ -918,7 +918,7 @@ window.__ModuleLoader__.load({
918
918
  const row = modes[mode] || {}
919
919
  return {
920
920
  chain: Array.isArray(row.chain) ? row.chain.map((e) => e && e.provider) : [],
921
- language: row.language || 'ru',
921
+ language: row.language !== undefined ? row.language : '',
922
922
  }
923
923
  })
924
924
  }
@@ -2403,7 +2403,10 @@ window.__ModuleLoader__.load({
2403
2403
  setInstallingSensevoice(true)
2404
2404
  fetch('/dsh-voice/sensevoice-installer', {
2405
2405
  method: 'POST',
2406
- headers: { 'x-dsh-plugin-update': '1' },
2406
+ headers: {
2407
+ 'x-dsh-plugin-update': '1',
2408
+ 'Content-Type': 'application/json',
2409
+ },
2407
2410
  })
2408
2411
  .then((r) => r.json())
2409
2412
  .then(() => {
package/lib/index.js CHANGED
@@ -32,39 +32,14 @@ import { createConfigReader } from './config-compat.js'
32
32
  import { registerConfigRoutes } from './config-routes.js'
33
33
  import { getAllowedAudioRoots, validateAudioPath, validateAudioContent } from './audio-guard.js'
34
34
  import { isAutoLang } from './provider-http.js'
35
+ import { ChainEntry, CustomProvider, BaseConfig } from './schema.js'
36
+ import { registerTranscribeAudioTool, MIME_BY_EXT } from './tool.js'
37
+ export { ChainEntry, CustomProvider, BaseConfig }
35
38
 
36
39
  export const name = '@goodandready/dsh-voice'
37
40
  export const NS = 'dsh-voice'
38
41
  export const inject = ['tools', 'credentials', 'webServer', 'shell', 'settings', 'llm']
39
42
 
40
- const ChainEntry = z.object({
41
- provider: z.string().default('local-whisper')
42
- .description(`Provider key. Built in: ${PROVIDER_KEYS.join(', ')}. `
43
- + `Ready-made, just add the key: ${PRESET_KEYS.join(', ')}. `
44
- + 'Or the name of an entry from customProviders. '
45
- + '"browser" recognises speech in the page itself — no key, no upload to this host, '
46
- + 'text appears while you speak; put a normal provider after it as a fallback.'),
47
- model: z.string().default('')
48
- .description('Model override. Empty means the provider default.'),
49
- })
50
-
51
- // Custom provider: everything needed to call any OpenAI-compatible API.
52
- const CustomProvider = z.object({
53
- key: z.string().default('')
54
- .description('Name used in the chains above. Must differ from the built-in keys.'),
55
- template: z.string().default('openai-transcriptions')
56
- .description(`API shape: ${CUSTOM_TEMPLATES.join(' or ')}. `
57
- + 'OpenRouter has no /audio/transcriptions, use openai-chat-audio there.'),
58
- baseURL: z.string().default('')
59
- .description('API root without a trailing slash, e.g. https://openrouter.ai/api/v1'),
60
- model: z.string().default(''),
61
- keyEnv: z.string().default('')
62
- .description('Credential name holding the API key. Empty means no authorization header.'),
63
- prompt: z.string().default('')
64
- .description('openai-chat-audio only: instruction sent along with the audio. '
65
- + 'Empty means the built-in one.'),
66
- })
67
-
68
43
  function makeVolatile(schema) {
69
44
  if (!schema || typeof schema.volatile !== 'function') return schema
70
45
  if (schema.type === 'object' && schema.dict) {
@@ -79,135 +54,10 @@ function makeVolatile(schema) {
79
54
  return schema.volatile()
80
55
  }
81
56
 
82
- const BaseConfig = z.object({
83
- dictation: z.object({
84
- chain: z.array(ChainEntry)
85
- .default([{ provider: 'deepgram', model: '' }, { provider: 'groq', model: '' }, { provider: 'local-whisper', model: '' }])
86
- .description('Fallback chain for dictation. Speed matters more than accuracy here.'),
87
- language: z.string().default('')
88
- .description('Recognition language code for dictation (e.g. "en", "ru", "zh", or empty string for auto-detection).'),
89
- vadSilenceMs: z.number().default(700)
90
- .description('Silence longer than this ends a phrase and sends the chunk.'),
91
- sendDelayMs: z.number().default(0)
92
- .description('Dictation: wait this many ms after a phrase before appending it, with a cancel window. 0 disables the delay.'),
93
- polish: z.boolean().default(false)
94
- .description('Polish the transcript through the harness model before inserting: punctuation, paragraphs, filler-word removal.'),
95
- stream: z.boolean().default(false)
96
- .description('Continuous dictation: cut phrases by a timer instead of waiting for a long silence, so text flows while you speak.'),
97
- streamChunkMs: z.number().default(1200)
98
- .description('Continuous dictation: phrase length in ms of uninterrupted speech before the chunk is sent.'),
99
- vadAdapt: z.number().min(0).max(1).default(0)
100
- .description('Adaptive silence threshold: 0 = fixed (current behaviour); >0 shrinks the threshold during dense speech and grows it during pauses.'),
101
- }).default({}),
102
- message: z.object({
103
- chain: z.array(ChainEntry)
104
- .default([{ provider: 'groq', model: '' }, { provider: 'hf', model: '' }, { provider: 'local-whisper', model: '' }])
105
- .description('Fallback chain for voice messages. Accuracy matters more than speed.'),
106
- language: z.string().default('')
107
- .description('Recognition language code for messages (e.g. "en", "ru", "zh", or empty string for auto-detection).'),
108
- autoSendMs: z.number().default(4000)
109
- .description('Cancel window before the recognized text is sent to the agent.'),
110
- sessionCommands: z.boolean().default(false)
111
- .description('Voice session commands: a clean "send", "cancel", "stop", "continue" does not become text — it drives the composer/session.'),
112
- polishSend: z.boolean().default(false)
113
- .description('Polish the whole composed draft through the model right before sending, not just single phrases.'),
114
- }).default({}),
115
- hotkey: z.string().default('Control')
116
- .description('Hold this key anywhere in the page to record a voice message; release to send, '
117
- + 'Escape to discard. Modifier names (Control, Alt, Shift) or a KeyboardEvent code. '
118
- + 'Empty disables the hotkey.'),
119
- customProviders: z.array(CustomProvider).default([])
120
- .description('Own recognition providers, usable in both chains next to the built-in ones.'),
121
- deepgramKeyEnv: z.string().default('DEEPGRAM_API_KEY'),
122
- deepgramBaseUrl: z.string().default('https://api.deepgram.com')
123
- .description('Deepgram-compatible host. Point this at a private/self-hosted Deepgram deployment '
124
- + 'instead of the public api.deepgram.com endpoint.'),
125
- groqKeyEnv: z.string().default('GROQ_API_KEY'),
126
- hfTokenEnv: z.string().default('HF_TOKEN'),
127
- whisperUrl: z.string().default('http://127.0.0.1:8001/inference'),
128
- whisperBin: z.string().default('whisper-server')
129
- .description('whisper.cpp server binary, looked up in PATH unless an absolute path is given.'),
130
- whisperModel: z.string().default('')
131
- .description('Absolute path to the ggml model. Autostart stays off while this is empty; '
132
- + 'point it at your own model file to let the plugin launch whisper.cpp itself.'),
133
- autoStart: z.boolean().default(true)
134
- .description('Launch the local whisper.cpp server on activation if the port is free. '
135
- + 'Requires whisperModel to be set.'),
136
- ffmpegBin: z.string().default('ffmpeg')
137
- .description('ffmpeg used to convert browser webm/opus into the WAV that whisper.cpp requires.'),
138
- timeoutMs: z.number().default(120000),
139
- allowedAudioDirs: z.array(z.string()).default([]),
140
- maxFileBytes: z.number().default(25 * 1024 * 1024),
141
- normalizeTranscript: z.boolean().default(false)
142
- .description('transcribe_audio: convert spoken numbers to digits and tidy punctuation.'),
143
- beep: z.boolean().default(false)
144
- .description('Play a short beep when recording starts and stops.'),
145
- localOnly: z.boolean().default(false)
146
- .description('Restrict both chains to local-whisper only: fully offline, no cloud providers.'),
147
- micDeviceId: z.string().default('')
148
- .description('Microphone device id for recording. Empty means the system default.'),
149
- noiseGateDb: z.number().default(-45)
150
- .description('Audio noise gate threshold in dB for client-side recording (-50 to -25 dB, or <= -90 to disable). Silence below this threshold cuts ambient background noise and prevents false VAD triggers.'),
151
- historyLimit: z.number().default(20)
152
- .description('How many recent dictation inserts to keep for undo in the browser. 0 disables history.'),
153
- vocabulary: z.array(z.string()).default([])
154
- .description('Custom words (names, terms) hinted to providers so they recognize them correctly.'),
155
- contextGlossary: z.boolean().default(true)
156
- .description('Automatically extract code words and terms from context and hint them to STT providers.'),
157
- noiseSuppression: z.boolean().default(true)
158
- .description('Enable hardware noise suppression, echo cancellation, and auto gain control.'),
159
- voiceCommands: z.boolean().default(false)
160
- .description('During dictation, spoken edit commands ("new line", "paragraph") become real line breaks instead of words.'),
161
- wakeWord: z.string().default('')
162
- .description('Heads-free dictation: a phrase that, when recognized by the browser leg, starts a recording. Empty disables.'),
163
- bargeIn: z.boolean().default(false)
164
- .description('Ongoing playback or a long turn is interrupted by detected speech (browser leg).'),
165
- polishBaseUrl: z.string().default('')
166
- .description('Offline polish: OpenAI-compatible /chat/completions endpoint (e.g. local Ollama). Empty uses the harness model.'),
167
- polishModel: z.string().default('')
168
- .description('Offline polish: model id on polishBaseUrl.'),
169
- polishKeyEnv: z.string().default('')
170
- .description('Offline polish: credential name for the api key. Empty means no Authorization header.'),
171
- polishProvider: z.string().default('')
172
- .description('Harness polish: provider id. Empty uses the agent default model selection.'),
173
- polishModelId: z.string().default('')
174
- .description('Harness polish: model id. Empty uses the agent default model selection.'),
175
- sensevoiceUrl: z.string().default('http://127.0.0.1:6006/api/v1/asr')
176
- .description('SenseVoice-ONNX / Sherpa-ONNX endpoint: POST /api/v1/asr or OpenAI-compatible /v1/audio/transcriptions.'),
177
- sensevoiceBin: z.string().default('sherpa-onnx-offline-http-server')
178
- .description('SenseVoice / sherpa-onnx executable binary used when autostart is enabled.'),
179
- sensevoiceModel: z.string().default('')
180
- .description('SenseVoice / sherpa-onnx model path or model identifier.'),
181
- sensevoiceAutostart: z.boolean().default(false)
182
- .description('Start the local SenseVoice / sherpa-onnx server process automatically on startup.'),
183
- visualizerStyle: z.union(['liquid-wave', 'dynamic-orb', 'bars', 'off']).default('liquid-wave')
184
- .description('Audio visualizer animation style in the recording pill: "liquid-wave", "dynamic-orb", "bars", or "off".'),
185
- gatedTurnTaking: z.boolean().default(true)
186
- .description('Gated mode for speakers: pause recording or ignore input while assistant TTS is speaking to prevent acoustic feedback.'),
187
- autoSendVisualRing: z.boolean().default(true)
188
- .description('Show animated circular countdown ring on recording pill before auto-sending.'),
189
- voiceActions: z.boolean().default(true)
190
- .description('Enable spoken action triggers ("send", "cancel", "clear", "new line" in English/Russian).'),
191
- techJargonCorrection: z.boolean().default(true)
192
- .description('Apply developer lexicon and IT jargon normalization (GitHub, Docker, pnpm, Kubernetes, etc.).'),
193
- jargonDictionary: z.array(z.object({ from: z.string(), to: z.string() })).default([])
194
- .description('Custom jargon replacement dictionary.'),
195
- liveInterimPreview: z.boolean().default(true)
196
- .description('Display real-time interim speech preview (ghost text) in the recording pill.'),
197
- structuredPromptVoice: z.boolean().default(true)
198
- .description('Target voice dictation and numeric choices to active DSH structured prompt modals.'),
199
- })
200
-
201
57
  export const Config = typeof z.number().volatile === 'function'
202
58
  ? makeVolatile(BaseConfig)
203
59
  : BaseConfig
204
60
 
205
- const MIME_BY_EXT = {
206
- '.wav': 'audio/wav', '.mp3': 'audio/mpeg', '.m4a': 'audio/mp4', '.mp4': 'audio/mp4',
207
- '.ogg': 'audio/ogg', '.oga': 'audio/ogg', '.flac': 'audio/flac', '.webm': 'audio/webm', '.aac': 'audio/aac',
208
- }
209
-
210
-
211
61
  export function apply(ctx, baseConfig) {
212
62
  let child = null
213
63
 
@@ -255,6 +105,10 @@ export function apply(ctx, baseConfig) {
255
105
  return true
256
106
  }
257
107
  try {
108
+ if (child && typeof child.kill === 'function') {
109
+ try { child.kill() } catch { /* ignore */ }
110
+ child = null
111
+ }
258
112
  const spec = ctx.shell.resolve({
259
113
  command: `${JSON.stringify(cfg.whisperBin)} -m ${JSON.stringify(cfg.whisperModel)}`
260
114
  + ` --host 127.0.0.1 --port 8001 -t 8 -p 1 -l ${isAutoLang(cfg.dictation.language) ? 'auto' : cfg.dictation.language}`,
@@ -321,6 +175,10 @@ export function apply(ctx, baseConfig) {
321
175
  return true
322
176
  }
323
177
  try {
178
+ if (sensevoiceChild && typeof sensevoiceChild.kill === 'function') {
179
+ try { sensevoiceChild.kill() } catch { /* ignore */ }
180
+ sensevoiceChild = null
181
+ }
324
182
  let port = '6006'
325
183
  try { port = new URL(cfg.sensevoiceUrl).port || '6006' } catch { /* invalid URL */ }
326
184
  const tokensPath = findTokensFile(path.dirname(cfg.sensevoiceModel))
@@ -602,62 +460,13 @@ export function apply(ctx, baseConfig) {
602
460
  },
603
461
  }), 'dsh-voice: /transcribe route')
604
462
 
605
- ctx.effect(() => ctx.tools.register(
606
- defineTool({
607
- name: 'transcribe_audio',
608
- description:
609
- 'Recognize speech in an audio file and return the transcript as text. '
610
- + 'Uses the voice-message fallback chain from the dsh-voice settings, so a single '
611
- + 'provider outage or rate limit does not fail the request. '
612
- + 'Use for voice messages, recordings, interviews.',
613
- parameters: {
614
- file_path: { type: 'string', required: true, description: 'Absolute path to the audio file (wav, mp3, m4a, ogg, flac, webm).' },
615
- language: { type: 'string', description: `Recognition language code (e.g. "en", "ru", "zh", or empty string for auto-detection). Default: ${(baseConfig && baseConfig.message && baseConfig.message.language) || 'auto'}.` },
616
- },
617
- output: {
618
- schema: {
619
- type: 'object',
620
- additionalProperties: false,
621
- properties: { provider: { type: 'string' }, text: { type: 'string' }, tookMs: { type: 'integer' } },
622
- },
623
- render(args, value) {
624
- const body = value.text.length > 4000
625
- ? `${value.text.slice(0, 4000)}\n…[truncated ${value.text.length} chars]`
626
- : value.text
627
- return [{ type: 'text', text: `transcribe_audio (${value.provider}, ${value.tookMs}ms):\n${body}` }]
628
- },
629
- },
630
- isConcurrencySafe: () => false,
631
- timeoutMs: 365000,
632
- async execute(args, exec) {
633
- const cfg = live()
634
- const filePath = String(args.file_path || '').trim()
635
- if (!filePath) throw new Error('transcribe_audio: file_path is required')
636
- const allowedRoots = getAllowedAudioRoots(cfg)
637
- const { real } = await validateAudioPath(filePath, allowedRoots)
638
- const info = await stat(real).catch(() => null)
639
- if (!info) throw new Error(`transcribe_audio: file not found: ${filePath}`)
640
- if (info.size > cfg.maxFileBytes) {
641
- throw new Error(`transcribe_audio: file too large (${info.size} bytes, max ${cfg.maxFileBytes})`)
642
- }
643
- if (info.size < 44) throw new Error('transcribe_audio: file is empty or too small')
644
- const bytes = await readFile(real)
645
- const sniffedMime = validateAudioContent(bytes)
646
- const mime = sniffedMime || MIME_BY_EXT[path.extname(real).toLowerCase()] || 'audio/wav'
647
- const modeCfg = { ...cfg.message, language: String(args.language !== undefined ? args.language : cfg.message.language) }
648
- let raw = await transcribe(modeCfg, bytes, mime, exec.signal)
649
- if (raw && raw.text) raw = { ...raw, text: await polishText(raw.text, modeCfg, exec.signal) }
650
- const out = raw
651
- if (cfg.normalizeTranscript && out && out.text) {
652
- out.text = normalizePhrase(out.text, {
653
- lang: modeCfg.language,
654
- digits: true, capSentences: true, commaSpacing: true, trailingPeriod: true,
655
- })
656
- }
657
- return out
658
- },
659
- }),
660
- ), 'dsh-voice: transcribe_audio tool')
463
+ // Registers agent tool name: 'transcribe_audio'
464
+ ctx.effect(() => registerTranscribeAudioTool(ctx, {
465
+ live,
466
+ baseConfig,
467
+ transcribe,
468
+ polishText,
469
+ }), 'dsh-voice: transcribe_audio tool')
661
470
 
662
471
  ctx.effect(() => () => {
663
472
  if (child) { try { child.kill && child.kill() } catch { /* already dead */ } }
package/lib/schema.js ADDED
@@ -0,0 +1,153 @@
1
+ // lib/schema.js — Schemastery configuration schemas for @goodandready/dsh-voice
2
+ import z from '@deepseek-ai/schemastery'
3
+ import { PROVIDER_KEYS, PRESET_KEYS, CUSTOM_TEMPLATES } from './providers.js'
4
+
5
+ export const ChainEntry = z.object({
6
+ provider: z.string().default('local-whisper')
7
+ .description(`Provider key. Built in: ${PROVIDER_KEYS.join(', ')}. `
8
+ + `Ready-made, just add the key: ${PRESET_KEYS.join(', ')}. `
9
+ + 'Or the name of an entry from customProviders. '
10
+ + '"browser" recognises speech in the page itself — no key, no upload to this host, '
11
+ + 'text appears while you speak; put a normal provider after it as a fallback.'),
12
+ model: z.string().default('')
13
+ .description('Model override. Empty means the provider default.'),
14
+ })
15
+
16
+ // Custom provider: everything needed to call any OpenAI-compatible API.
17
+ export const CustomProvider = z.object({
18
+ key: z.string().default('')
19
+ .description('Name used in the chains above. Must differ from the built-in keys.'),
20
+ template: z.string().default('openai-transcriptions')
21
+ .description(`API shape: ${CUSTOM_TEMPLATES.join(' or ')}. `
22
+ + 'OpenRouter has no /audio/transcriptions, use openai-chat-audio there.'),
23
+ baseURL: z.string().default('')
24
+ .description('API root without a trailing slash, e.g. https://openrouter.ai/api/v1'),
25
+ model: z.string().default(''),
26
+ keyEnv: z.string().default('')
27
+ .description('Credential name holding the API key. Empty means no authorization header.'),
28
+ prompt: z.string().default('')
29
+ .description('openai-chat-audio only: instruction sent along with the audio. '
30
+ + 'Empty means the built-in one.'),
31
+ })
32
+
33
+
34
+ export const BaseConfig = z.object({
35
+ dictation: z.object({
36
+ chain: z.array(ChainEntry)
37
+ .default([{ provider: 'deepgram', model: '' }, { provider: 'groq', model: '' }, { provider: 'local-whisper', model: '' }])
38
+ .description('Fallback chain for dictation. Speed matters more than accuracy here.'),
39
+ language: z.string().default('')
40
+ .description('Recognition language code for dictation (e.g. "en", "ru", "zh", or empty string for auto-detection).'),
41
+ vadSilenceMs: z.number().default(700)
42
+ .description('Silence longer than this ends a phrase and sends the chunk.'),
43
+ sendDelayMs: z.number().default(0)
44
+ .description('Dictation: wait this many ms after a phrase before appending it, with a cancel window. 0 disables the delay.'),
45
+ polish: z.boolean().default(false)
46
+ .description('Polish the transcript through the harness model before inserting: punctuation, paragraphs, filler-word removal.'),
47
+ stream: z.boolean().default(false)
48
+ .description('Continuous dictation: cut phrases by a timer instead of waiting for a long silence, so text flows while you speak.'),
49
+ streamChunkMs: z.number().default(1200)
50
+ .description('Continuous dictation: phrase length in ms of uninterrupted speech before the chunk is sent.'),
51
+ vadAdapt: z.number().min(0).max(1).default(0)
52
+ .description('Adaptive silence threshold: 0 = fixed (current behaviour); >0 shrinks the threshold during dense speech and grows it during pauses.'),
53
+ }).default({}),
54
+ message: z.object({
55
+ chain: z.array(ChainEntry)
56
+ .default([{ provider: 'groq', model: '' }, { provider: 'hf', model: '' }, { provider: 'local-whisper', model: '' }])
57
+ .description('Fallback chain for voice messages. Accuracy matters more than speed.'),
58
+ language: z.string().default('')
59
+ .description('Recognition language code for messages (e.g. "en", "ru", "zh", or empty string for auto-detection).'),
60
+ autoSendMs: z.number().default(4000)
61
+ .description('Cancel window before the recognized text is sent to the agent.'),
62
+ sessionCommands: z.boolean().default(false)
63
+ .description('Voice session commands: a clean "send", "cancel", "stop", "continue" does not become text — it drives the composer/session.'),
64
+ polishSend: z.boolean().default(false)
65
+ .description('Polish the whole composed draft through the model right before sending, not just single phrases.'),
66
+ }).default({}),
67
+ hotkey: z.string().default('Control')
68
+ .description('Hold this key anywhere in the page to record a voice message; release to send, '
69
+ + 'Escape to discard. Modifier names (Control, Alt, Shift) or a KeyboardEvent code. '
70
+ + 'Empty disables the hotkey.'),
71
+ customProviders: z.array(CustomProvider).default([])
72
+ .description('Own recognition providers, usable in both chains next to the built-in ones.'),
73
+ deepgramKeyEnv: z.string().default('DEEPGRAM_API_KEY'),
74
+ deepgramBaseUrl: z.string().default('https://api.deepgram.com')
75
+ .description('Deepgram-compatible host. Point this at a private/self-hosted Deepgram deployment '
76
+ + 'instead of the public api.deepgram.com endpoint.'),
77
+ groqKeyEnv: z.string().default('GROQ_API_KEY'),
78
+ hfTokenEnv: z.string().default('HF_TOKEN'),
79
+ whisperUrl: z.string().default('http://127.0.0.1:8001/inference'),
80
+ whisperBin: z.string().default('whisper-server')
81
+ .description('whisper.cpp server binary, looked up in PATH unless an absolute path is given.'),
82
+ whisperModel: z.string().default('')
83
+ .description('Absolute path to the ggml model. Autostart stays off while this is empty; '
84
+ + 'point it at your own model file to let the plugin launch whisper.cpp itself.'),
85
+ autoStart: z.boolean().default(true)
86
+ .description('Launch the local whisper.cpp server on activation if the port is free. '
87
+ + 'Requires whisperModel to be set.'),
88
+ ffmpegBin: z.string().default('ffmpeg')
89
+ .description('ffmpeg used to convert browser webm/opus into the WAV that whisper.cpp requires.'),
90
+ timeoutMs: z.number().default(120000),
91
+ allowedAudioDirs: z.array(z.string()).default([]),
92
+ maxFileBytes: z.number().default(25 * 1024 * 1024),
93
+ normalizeTranscript: z.boolean().default(false)
94
+ .description('transcribe_audio: convert spoken numbers to digits and tidy punctuation.'),
95
+ beep: z.boolean().default(false)
96
+ .description('Play a short beep when recording starts and stops.'),
97
+ localOnly: z.boolean().default(false)
98
+ .description('Restrict both chains to local-whisper only: fully offline, no cloud providers.'),
99
+ micDeviceId: z.string().default('')
100
+ .description('Microphone device id for recording. Empty means the system default.'),
101
+ noiseGateDb: z.number().default(-45)
102
+ .description('Audio noise gate threshold in dB for client-side recording (-50 to -25 dB, or <= -90 to disable). Silence below this threshold cuts ambient background noise and prevents false VAD triggers.'),
103
+ historyLimit: z.number().default(20)
104
+ .description('How many recent dictation inserts to keep for undo in the browser. 0 disables history.'),
105
+ vocabulary: z.array(z.string()).default([])
106
+ .description('Custom words (names, terms) hinted to providers so they recognize them correctly.'),
107
+ contextGlossary: z.boolean().default(true)
108
+ .description('Automatically extract code words and terms from context and hint them to STT providers.'),
109
+ noiseSuppression: z.boolean().default(true)
110
+ .description('Enable hardware noise suppression, echo cancellation, and auto gain control.'),
111
+ voiceCommands: z.boolean().default(false)
112
+ .description('During dictation, spoken edit commands ("new line", "paragraph") become real line breaks instead of words.'),
113
+ wakeWord: z.string().default('')
114
+ .description('Heads-free dictation: a phrase that, when recognized by the browser leg, starts a recording. Empty disables.'),
115
+ bargeIn: z.boolean().default(false)
116
+ .description('Ongoing playback or a long turn is interrupted by detected speech (browser leg).'),
117
+ polishBaseUrl: z.string().default('')
118
+ .description('Offline polish: OpenAI-compatible /chat/completions endpoint (e.g. local Ollama). Empty uses the harness model.'),
119
+ polishModel: z.string().default('')
120
+ .description('Offline polish: model id on polishBaseUrl.'),
121
+ polishKeyEnv: z.string().default('')
122
+ .description('Offline polish: credential name for the api key. Empty means no Authorization header.'),
123
+ polishProvider: z.string().default('')
124
+ .description('Harness polish: provider id. Empty uses the agent default model selection.'),
125
+ polishModelId: z.string().default('')
126
+ .description('Harness polish: model id. Empty uses the agent default model selection.'),
127
+ sensevoiceUrl: z.string().default('http://127.0.0.1:6006/api/v1/asr')
128
+ .description('SenseVoice-ONNX / Sherpa-ONNX endpoint: POST /api/v1/asr or OpenAI-compatible /v1/audio/transcriptions.'),
129
+ sensevoiceBin: z.string().default('sherpa-onnx-offline-http-server')
130
+ .description('SenseVoice / sherpa-onnx executable binary used when autostart is enabled.'),
131
+ sensevoiceModel: z.string().default('')
132
+ .description('SenseVoice / sherpa-onnx model path or model identifier.'),
133
+ sensevoiceAutostart: z.boolean().default(false)
134
+ .description('Start the local SenseVoice / sherpa-onnx server process automatically on startup.'),
135
+ visualizerStyle: z.union(['liquid-wave', 'dynamic-orb', 'bars', 'off']).default('liquid-wave')
136
+ .description('Audio visualizer animation style in the recording pill: "liquid-wave", "dynamic-orb", "bars", or "off".'),
137
+ gatedTurnTaking: z.boolean().default(true)
138
+ .description('Gated mode for speakers: pause recording or ignore input while assistant TTS is speaking to prevent acoustic feedback.'),
139
+ autoSendVisualRing: z.boolean().default(true)
140
+ .description('Show animated circular countdown ring on recording pill before auto-sending.'),
141
+ voiceActions: z.boolean().default(true)
142
+ .description('Enable spoken action triggers ("send", "cancel", "clear", "new line" in English/Russian).'),
143
+ techJargonCorrection: z.boolean().default(true)
144
+ .description('Apply developer lexicon and IT jargon normalization (GitHub, Docker, pnpm, Kubernetes, etc.).'),
145
+ jargonDictionary: z.array(z.object({ from: z.string(), to: z.string() })).default([])
146
+ .description('Custom jargon replacement dictionary.'),
147
+ liveInterimPreview: z.boolean().default(true)
148
+ .description('Display real-time interim speech preview (ghost text) in the recording pill.'),
149
+ structuredPromptVoice: z.boolean().default(true)
150
+ .description('Target voice dictation and numeric choices to active DSH structured prompt modals.'),
151
+ })
152
+
153
+
package/lib/tool.js ADDED
@@ -0,0 +1,69 @@
1
+ import { defineTool } from '@deepseek-ai/dsh-tools'
2
+ import { readFile, stat } from 'node:fs/promises'
3
+ import path from 'node:path'
4
+ import { getAllowedAudioRoots, validateAudioPath, validateAudioContent } from './audio-guard.js'
5
+ import { normalizePhrase } from './normalize.js'
6
+
7
+ export const MIME_BY_EXT = {
8
+ '.wav': 'audio/wav', '.mp3': 'audio/mpeg', '.m4a': 'audio/mp4', '.mp4': 'audio/mp4',
9
+ '.ogg': 'audio/ogg', '.oga': 'audio/ogg', '.flac': 'audio/flac', '.webm': 'audio/webm', '.aac': 'audio/aac',
10
+ }
11
+
12
+ export function registerTranscribeAudioTool(ctx, { live, baseConfig, transcribe, polishText }) {
13
+ return ctx.tools.register(
14
+ defineTool({
15
+ name: 'transcribe_audio',
16
+ description:
17
+ 'Recognize speech in an audio file and return the transcript as text. '
18
+ + 'Uses the voice-message fallback chain from the dsh-voice settings, so a single '
19
+ + 'provider outage or rate limit does not fail the request. '
20
+ + 'Use for voice messages, recordings, interviews.',
21
+ parameters: {
22
+ file_path: { type: 'string', required: true, description: 'Absolute path to the audio file (wav, mp3, m4a, ogg, flac, webm).' },
23
+ language: { type: 'string', description: `Recognition language code (e.g. "en", "ru", "zh", or empty string for auto-detection). Default: ${(baseConfig && baseConfig.message && baseConfig.message.language) || 'auto'}.` },
24
+ },
25
+ output: {
26
+ schema: {
27
+ type: 'object',
28
+ additionalProperties: false,
29
+ properties: { provider: { type: 'string' }, text: { type: 'string' }, tookMs: { type: 'integer' } },
30
+ },
31
+ render(args, value) {
32
+ const body = value.text.length > 4000
33
+ ? `${value.text.slice(0, 4000)}\n…[truncated ${value.text.length} chars]`
34
+ : value.text
35
+ return [{ type: 'text', text: `transcribe_audio (${value.provider}, ${value.tookMs}ms):\n${body}` }]
36
+ },
37
+ },
38
+ isConcurrencySafe: () => false,
39
+ timeoutMs: 365000,
40
+ async execute(args, exec) {
41
+ const cfg = live()
42
+ const filePath = String(args.file_path || '').trim()
43
+ if (!filePath) throw new Error('transcribe_audio: file_path is required')
44
+ const allowedRoots = getAllowedAudioRoots(cfg)
45
+ const { real } = await validateAudioPath(filePath, allowedRoots)
46
+ const info = await stat(real).catch(() => null)
47
+ if (!info) throw new Error(`transcribe_audio: file not found: ${filePath}`)
48
+ if (info.size > cfg.maxFileBytes) {
49
+ throw new Error(`transcribe_audio: file too large (${info.size} bytes, max ${cfg.maxFileBytes})`)
50
+ }
51
+ if (info.size < 44) throw new Error('transcribe_audio: file is empty or too small')
52
+ const bytes = await readFile(real)
53
+ const sniffedMime = validateAudioContent(bytes)
54
+ const mime = sniffedMime || MIME_BY_EXT[path.extname(real).toLowerCase()] || 'audio/wav'
55
+ const modeCfg = { ...cfg.message, language: String(args.language !== undefined ? args.language : cfg.message.language) }
56
+ let raw = await transcribe(modeCfg, bytes, mime, exec.signal)
57
+ if (raw && raw.text) raw = { ...raw, text: await polishText(raw.text, modeCfg, exec.signal) }
58
+ const out = raw
59
+ if (cfg.normalizeTranscript && out && out.text) {
60
+ out.text = normalizePhrase(out.text, {
61
+ lang: modeCfg.language,
62
+ digits: true, capSentences: true, commaSpacing: true, trailingPeriod: true,
63
+ })
64
+ }
65
+ return out
66
+ },
67
+ }),
68
+ )
69
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodandready/dsh-voice",
3
- "version": "0.9.4",
3
+ "version": "0.9.6",
4
4
  "description": "Voice input for DeepSeek Harness: dictation chunked by pauses and voice messages, each with its own provider fallback chain (Deepgram, Groq, HuggingFace, local whisper.cpp, plus any OpenAI-compatible API of your own).",
5
5
  "license": "MIT",
6
6
  "type": "module",