iobroker.assistant 1.9.0 → 1.9.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"engines.js","sourceRoot":"","sources":["../../../src/lib/voice/engines.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwHA,0CAYC;AA+BD,0CAGC;AA2ID,gCAmBC;AAGD,sCAKC;AAMD,sCAKC;AAvVD;;;;GAIG;AACH,+BAAkD;AAClD,+BAAoE;AACpE,mCAA8D;AAC9D,+BAAuE;AACvE,iCAAiD;AACjD,yCAA6D;AAC7D,mCAAoD;AACpD,6CAOsB;AACtB,gDAAkC;AAElC,yCAAuC;AACvC,yCAAwE;AACxE,iCAAqC;AACrC,qDAAqF;AAuErF,SAAS,YAAY,CAAC,KAAuB;IACzC,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACxE,CAAC;AACL,CAAC;AAED,SAAS,UAAU,CAAC,KAAuB;IACvC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,eAAe,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QAC5E,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;IACvF,CAAC;AACL,CAAC;AAED,SAAS,aAAa,CAAC,KAAuB;IAC1C,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACtD,CAAC;AACL,CAAC;AAED,SAAS,iBAAiB,CAAC,KAAuB;IAC9C,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAA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C1D,CAAC","sourcesContent":["/**\n * Factory that builds the configured STT/TTS engine. Cloud engines (OpenAI/Azure/AWS) use resolved\n * credentials; local engines (Vosk/Piper) download their models on demand into the data dir.\n * Adding a provider = one new engine class + one `case` here.\n */\nimport { OpenAiStt, type SttEngine } from './stt';\nimport { OpenAiTts, type OpenAiVoice, type TtsEngine } from './tts';\nimport { AzureStt, AzureTts, listAzureVoices } from './azure';\nimport { AwsStt, AwsTts, listPollyVoices, type AwsCreds } from './aws';\nimport { VoskStt, listVoskModels } from './vosk';\nimport { ParakeetStt, type MessageSender } from './parakeet';\nimport { PiperTts, listPiperVoices } from './piper';\nimport {\n OpenRouterStt,\n OpenRouterTts,\n listOpenRouterSpeechModels,\n voicesForLanguage,\n DEFAULT_OPENROUTER_TTS_MODEL,\n type AudioDecoder,\n} from './openrouter';\nimport * as path from 'node:path';\n\nimport { CachedTts } from './ttsCache';\nimport { FallbackStt, FallbackTts, type NamedEngine } from './fallback';\nimport { isoToLocale } from './lang';\nimport { LanguageTts, VoicePerLanguage, type LanguageVoice } from './speechLanguage';\nimport type { VoiceLogger } from './download';\n\nexport type SpeechProvider = 'openai' | 'openrouter' | 'azure' | 'aws' | 'vosk' | 'parakeet' | 'piper';\n\n/** All speech credentials, resolved from config (or the central credential store). */\nexport interface VoiceCredentials {\n openaiKey: string;\n openrouterKey: string;\n azureKey: string;\n azureRegion: string;\n aws: AwsCreds;\n}\n\n/** Provider-specific voice ids (each provider names voices differently). */\nexport interface VoiceNames {\n openai: string; // alloy/echo/…\n azure: string; // e.g. de-DE-KatjaNeural\n aws: string; // e.g. Vicki\n piper: string; // e.g. de_DE-thorsten-medium\n openrouter: string; // depends on the model, e.g. Kore, george\n}\n\n/** Everything the factory needs to build any engine. */\nexport interface EngineContext {\n creds: VoiceCredentials;\n voices: VoiceNames;\n /** Optional second engine, used when the primary one fails ('' = none). */\n sttFallback?: SpeechProvider | '';\n ttsFallback?: SpeechProvider | '';\n /** Writable instance data dir (for the local engines' downloads). */\n dataDir: string;\n log: VoiceLogger;\n /** Local model overrides ('' → default per language). */\n voskModel: string;\n /** OpenAI STT model ('' → 'whisper-1'; e.g. 'gpt-4o-transcribe'). */\n sttModel: string;\n /**\n * OpenAI-compatible transcription server instead of OpenAI ('' = OpenAI), e.g. a local whisper container.\n * It gets `sttServerKey`, never the OpenAI key — that one is only for OpenAI.\n */\n sttBaseUrl?: string;\n /** Key for `sttBaseUrl` ('' = the server needs none). */\n sttServerKey?: string;\n /** OpenAI TTS model ('' → 'tts-1'; e.g. 'gpt-4o-mini-tts'). */\n ttsModel: string;\n /** OpenRouter models ('' → the defaults of openrouter.ts) */\n openrouterSttModel: string;\n openrouterTtsModel: string;\n /** Decoder for compressed speech (OpenRouter models that only return mp3); absent → those models fail */\n decodeAudio?: AudioDecoder;\n /** Longest text that is spoken, in characters; longer ones are cut at a sentence end. 0 = no limit, absent = 400. */\n ttsMaxChars?: number;\n /**\n * Language the satellites listen in (ISO-639-1). A voice set for one language (Polly 'Vicki') is only used for\n * it; an answer in another language gets the default voice of that language.\n */\n language?: string;\n /**\n * Table \"voice per language\" (ISO code → voice and/or model of the main TTS provider); absent = the voices above.\n * A model only for OpenAI and OpenRouter, the others have no choice.\n */\n voicesByLanguage?: Record<string, LanguageVoice>;\n /** Language the answering tier reported for exactly this text (pi-agent `language`); absent → by its letters. */\n reportedLanguage?: (text: string) => string | undefined;\n /** Instance of ioBroker.ai-parakeet for the provider `parakeet`, e.g. 'ai-parakeet.0'. */\n parakeetInstance?: string;\n /** Message bus to other instances (ai-parakeet); absent → `parakeet` cannot be used. */\n sendMessage?: MessageSender;\n}\n\nfunction requireAzure(creds: VoiceCredentials): void {\n if (!creds.azureKey || !creds.azureRegion) {\n throw new Error('Azure speech needs a subscription key and region');\n }\n}\n\nfunction requireAws(creds: VoiceCredentials): void {\n if (!creds.aws.accessKeyId || !creds.aws.secretAccessKey || !creds.aws.region) {\n throw new Error('AWS speech needs an access key id, secret access key and region');\n }\n}\n\nfunction requireOpenAi(creds: VoiceCredentials): void {\n if (!creds.openaiKey) {\n throw new Error('OpenAI speech needs an API key');\n }\n}\n\nfunction requireOpenRouter(creds: VoiceCredentials): void {\n if (!creds.openrouterKey) {\n throw new Error('OpenRouter speech needs an API key');\n }\n}\n\nexport function createSttEngine(provider: SpeechProvider, ctx: EngineContext): SttEngine {\n const primary: NamedEngine<SttEngine> = { name: provider, engine: buildSttEngine(provider, ctx) };\n const fallback = ctx.sttFallback && ctx.sttFallback !== provider ? ctx.sttFallback : '';\n if (!fallback) {\n return primary.engine;\n }\n try {\n return new FallbackStt([primary, { name: fallback, engine: buildSttEngine(fallback, ctx) }], ctx.log);\n } catch (e) {\n ctx.log.warn(`Speech-to-text fallback '${fallback}' unavailable: ${(e as Error).message}`);\n return primary.engine;\n }\n}\n\nfunction buildSttEngine(provider: SpeechProvider, ctx: EngineContext): SttEngine {\n switch (provider) {\n case 'azure':\n requireAzure(ctx.creds);\n return new AzureStt(ctx.creds.azureKey, ctx.creds.azureRegion);\n case 'aws':\n requireAws(ctx.creds);\n return new AwsStt(ctx.creds.aws);\n case 'vosk':\n return new VoskStt(ctx.dataDir, ctx.voskModel, ctx.log);\n case 'parakeet':\n if (!ctx.sendMessage) {\n throw new Error('Parakeet speech recognition is not available here');\n }\n return new ParakeetStt((ctx.parakeetInstance || '').trim(), ctx.sendMessage);\n case 'openrouter':\n requireOpenRouter(ctx.creds);\n return new OpenRouterStt(ctx.creds.openrouterKey, ctx.openrouterSttModel);\n case 'piper':\n throw new Error('Piper is a text-to-speech engine, not speech-to-text');\n default:\n if (ctx.sttBaseUrl?.trim()) {\n return new OpenAiStt(ctx.sttServerKey || '', ctx.sttModel || undefined, ctx.sttBaseUrl);\n }\n requireOpenAi(ctx.creds);\n return new OpenAiStt(ctx.creds.openaiKey, ctx.sttModel || undefined);\n }\n}\n\nexport function createTtsEngine(provider: SpeechProvider, ctx: EngineContext): TtsEngine {\n // Outermost: every text is spoken in its own language — a German voice spells a Russian answer letter by letter\n return new LanguageTts(fallbackTts(provider, ctx), ctx.reportedLanguage, ctx.log);\n}\n\nfunction fallbackTts(provider: SpeechProvider, ctx: EngineContext): TtsEngine {\n // Each engine gets the shared behaviour (disk cache, length limit, SSML) and its own cache directory,\n // so a fallback engine's voice can never be served later while the primary one is healthy again.\n const primary: NamedEngine<TtsEngine> = { name: provider, engine: withLanguageVoices(provider, ctx) };\n const fallback = ctx.ttsFallback && ctx.ttsFallback !== provider ? ctx.ttsFallback : '';\n if (!fallback) {\n return primary.engine;\n }\n try {\n return new FallbackTts([primary, { name: fallback, engine: cachedTts(fallback, ctx) }], ctx.log);\n } catch (e) {\n // A fallback that cannot even be built (missing key, wrong provider) must not take the main one down.\n ctx.log.warn(`Text-to-speech fallback '${fallback}' unavailable: ${(e as Error).message}`);\n return primary.engine;\n }\n}\n\n/** Key of a provider in {@link VoiceNames}; the speech-to-text-only providers have no voice. */\nfunction voiceKey(provider: SpeechProvider): keyof VoiceNames | '' {\n return provider === 'vosk' || provider === 'parakeet' ? '' : provider;\n}\n\n/** Providers whose TTS model can be chosen. */\nfunction hasTtsModel(provider: SpeechProvider): boolean {\n return provider === 'openai' || provider === 'openrouter';\n}\n\n/**\n * The engine context of one row of the table \"voice per language\": its voice and model instead of the ones set above.\n * Another OpenRouter model without a voice of its own gets none — the voices belong to the model, the engine then\n * takes the first one of the model for the language.\n */\nfunction rowContext(\n provider: SpeechProvider,\n key: keyof VoiceNames,\n lang: string,\n row: LanguageVoice,\n ctx: EngineContext,\n): EngineContext {\n const model = hasTtsModel(provider) ? row.model : '';\n const otherModel =\n provider === 'openrouter' && !!model && model !== (ctx.openrouterTtsModel || DEFAULT_OPENROUTER_TTS_MODEL);\n const voice = row.voice || (otherModel ? '' : ctx.voices[key]);\n return {\n ...ctx,\n // the voice of a row is for its language (Polly names say nothing about it)\n language: lang,\n voices: { ...ctx.voices, [key]: voice },\n ttsModel: provider === 'openai' && model ? model : ctx.ttsModel,\n openrouterTtsModel: provider === 'openrouter' && model ? model : ctx.openrouterTtsModel,\n };\n}\n\n/**\n * The main provider with the table \"voice per language\": one engine per row with that voice and model. The table\n * names voices and models of the main provider, so the fallback provider does not get it.\n */\nfunction withLanguageVoices(provider: SpeechProvider, ctx: EngineContext): TtsEngine {\n const main = cachedTts(provider, ctx);\n const key = voiceKey(provider);\n const rows = Object.entries(ctx.voicesByLanguage || {});\n if (!key || !rows.length) {\n return main;\n }\n const byLanguage: Record<string, TtsEngine> = {};\n for (const [lang, row] of rows) {\n if (row.model && !hasTtsModel(provider)) {\n ctx.log.warn(`TTS model '${row.model}' for '${lang}' ignored: ${provider} has no model choice`);\n if (!row.voice) {\n continue;\n }\n }\n try {\n byLanguage[lang] = cachedTts(provider, rowContext(provider, key, lang, row, ctx));\n } catch (e) {\n ctx.log.warn(`Voice '${row.voice || row.model}' for '${lang}' unavailable: ${(e as Error).message}`);\n }\n }\n return new VoicePerLanguage(main, byLanguage);\n}\n\n/**\n * One provider binding plus the shared cache/length/SSML layer. One cache directory per provider+voice —\n * a voice change must not serve audio in the old voice.\n */\nfunction cachedTts(provider: SpeechProvider, ctx: EngineContext): TtsEngine {\n const voice =\n provider === 'azure'\n ? ctx.voices.azure\n : provider === 'aws'\n ? ctx.voices.aws\n : provider === 'piper'\n ? ctx.voices.piper\n : provider === 'openrouter'\n ? `${ctx.openrouterTtsModel || DEFAULT_OPENROUTER_TTS_MODEL}-${ctx.voices.openrouter}`\n : // the model too: another model must not serve the audio of the old one\n `${ctx.ttsModel ? `${ctx.ttsModel}-` : ''}${ctx.voices.openai}`;\n const dir = path.join(ctx.dataDir, 'ttscache', `${provider}-${(voice || 'default').replace(/[^\\w.-]/g, '_')}`);\n return new CachedTts(buildTtsEngine(provider, ctx), { dir, log: ctx.log, maxChars: ctx.ttsMaxChars });\n}\n\nfunction buildTtsEngine(provider: SpeechProvider, ctx: EngineContext): TtsEngine {\n switch (provider) {\n case 'azure':\n requireAzure(ctx.creds);\n return new AzureTts(ctx.creds.azureKey, ctx.creds.azureRegion, ctx.voices.azure);\n case 'aws':\n requireAws(ctx.creds);\n return new AwsTts(ctx.creds.aws, ctx.voices.aws, ctx.language);\n case 'piper':\n return new PiperTts(ctx.dataDir, ctx.voices.piper, ctx.log);\n case 'vosk':\n throw new Error('Vosk is a speech-to-text engine, not text-to-speech');\n case 'parakeet':\n throw new Error('Parakeet is a speech-to-text engine, not text-to-speech');\n case 'openrouter':\n requireOpenRouter(ctx.creds);\n return new OpenRouterTts(\n ctx.creds.openrouterKey,\n ctx.openrouterTtsModel,\n ctx.voices.openrouter,\n ctx.decodeAudio,\n );\n default:\n requireOpenAi(ctx.creds);\n return new OpenAiTts(\n ctx.creds.openaiKey,\n (ctx.voices.openai || 'alloy') as OpenAiVoice,\n ctx.ttsModel || undefined,\n );\n }\n}\n\n/** OpenAI TTS voices are a fixed set (no list API). */\nconst OPENAI_VOICES = ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'];\n\n/** List the available TTS voices for a provider (for the settings voice dropdown). */\nexport async function listVoices(provider: SpeechProvider, ctx: EngineContext, language: string): Promise<string[]> {\n switch (provider) {\n case 'azure':\n requireAzure(ctx.creds);\n return listAzureVoices(ctx.creds.azureKey, ctx.creds.azureRegion, isoToLocale(language));\n case 'aws':\n requireAws(ctx.creds);\n return listPollyVoices(ctx.creds.aws, isoToLocale(language));\n case 'piper':\n return listPiperVoices();\n case 'openrouter': {\n // public list, no key needed: the voices of the chosen model\n const model = ctx.openrouterTtsModel || DEFAULT_OPENROUTER_TTS_MODEL;\n const models = await listOpenRouterSpeechModels('speech');\n return voicesForLanguage(models.find(m => m.id === model)?.voices || [], language);\n }\n default:\n return OPENAI_VOICES;\n }\n}\n\n/** Suggested STT model names for the settings dropdown: the local Vosk catalogue, or the models of OpenRouter. */\nexport async function listSttModels(provider: SpeechProvider, language: string): Promise<string[]> {\n if (provider === 'openrouter') {\n return (await listOpenRouterSpeechModels('transcription')).map(m => m.id);\n }\n return provider === 'vosk' ? listVoskModels(language) : [];\n}\n\n/** OpenAI TTS models (no list API that tells speech models apart). */\nconst OPENAI_TTS_MODELS = ['tts-1', 'tts-1-hd', 'gpt-4o-mini-tts'];\n\n/** TTS model names for the settings dropdown; the other providers have no model choice. */\nexport async function listTtsModels(provider: SpeechProvider): Promise<string[]> {\n if (provider === 'openrouter') {\n return (await listOpenRouterSpeechModels('speech')).map(m => m.id);\n }\n return provider === 'openai' ? OPENAI_TTS_MODELS : [];\n}\n"]}
1
+ {"version":3,"file":"engines.js","sourceRoot":"","sources":["../../../src/lib/voice/engines.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwHA,0CAYC;AA+BD,0CAGC;AA2ID,gCAmBC;AAGD,sCAKC;AAMD,sCAKC;AAvVD;;;;GAIG;AACH,+BAAkD;AAClD,+BAAoE;AACpE,mCAA8D;AAC9D,+BAAuE;AACvE,iCAAiD;AACjD,yCAA6D;AAC7D,mCAAoD;AACpD,6CAOsB;AACtB,gDAAkC;AAElC,yCAAuC;AACvC,yCAAwE;AACxE,iCAAqC;AACrC,qDAAqF;AAuErF,SAAS,YAAY,CAAC,KAAuB;IACzC,IAAI,CAAC,KAAK,CAAC,QAAQ,IAAI,CAAC,KAAK,CAAC,WAAW,EAAE,CAAC;QACxC,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACxE,CAAC;AACL,CAAC;AAED,SAAS,UAAU,CAAC,KAAuB;IACvC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,eAAe,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC;QAC5E,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;IACvF,CAAC;AACL,CAAC;AAED,SAAS,aAAa,CAAC,KAAuB;IAC1C,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC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AC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,QAAQ,KAAK,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,CAAC;AAC1D,CAAC","sourcesContent":["/**\n * Factory that builds the configured STT/TTS engine. Cloud engines (OpenAI/Azure/AWS) use resolved\n * credentials; local engines (Vosk/Piper) download their models on demand into the data dir.\n * Adding a provider = one new engine class + one `case` here.\n */\nimport { OpenAiStt, type SttEngine } from './stt';\nimport { OpenAiTts, type OpenAiVoice, type TtsEngine } from './tts';\nimport { AzureStt, AzureTts, listAzureVoices } from './azure';\nimport { AwsStt, AwsTts, listPollyVoices, type AwsCreds } from './aws';\nimport { VoskStt, listVoskModels } from './vosk';\nimport { ParakeetStt, type MessageSender } from './parakeet';\nimport { PiperTts, listPiperVoices } from './piper';\nimport {\n OpenRouterStt,\n OpenRouterTts,\n listOpenRouterSpeechModels,\n voicesForLanguage,\n DEFAULT_OPENROUTER_TTS_MODEL,\n type AudioDecoder,\n} from './openrouter';\nimport * as path from 'node:path';\n\nimport { CachedTts } from './ttsCache';\nimport { FallbackStt, FallbackTts, type NamedEngine } from './fallback';\nimport { isoToLocale } from './lang';\nimport { LanguageTts, VoicePerLanguage, type LanguageVoice } from './speechLanguage';\nimport type { VoiceLogger } from './download';\n\nexport type SpeechProvider = 'openai' | 'openrouter' | 'azure' | 'aws' | 'vosk' | 'parakeet' | 'piper';\n\n/** All speech credentials, resolved from config (or the central credential store). */\nexport interface VoiceCredentials {\n openaiKey: string;\n openrouterKey: string;\n azureKey: string;\n azureRegion: string;\n aws: AwsCreds;\n}\n\n/** Provider-specific voice ids (each provider names voices differently). */\nexport interface VoiceNames {\n openai: string; // alloy/echo/…\n azure: string; // e.g. de-DE-KatjaNeural\n aws: string; // e.g. Vicki\n piper: string; // e.g. de_DE-thorsten-medium\n openrouter: string; // depends on the model, e.g. Kore, george\n}\n\n/** Everything the factory needs to build any engine. */\nexport interface EngineContext {\n creds: VoiceCredentials;\n voices: VoiceNames;\n /** Optional second engine, used when the primary one fails ('' = none). */\n sttFallback?: SpeechProvider | '';\n ttsFallback?: SpeechProvider | '';\n /** Writable instance data dir (for the local engines' downloads). */\n dataDir: string;\n log: VoiceLogger;\n /** Local model overrides ('' → default per language). */\n voskModel: string;\n /** OpenAI STT model ('' → 'whisper-1'; e.g. 'gpt-4o-transcribe'). */\n sttModel: string;\n /**\n * OpenAI-compatible transcription server instead of OpenAI ('' = OpenAI), e.g. a local whisper container.\n * It gets `sttServerKey`, never the OpenAI key — that one is only for OpenAI.\n */\n sttBaseUrl?: string;\n /** Key for `sttBaseUrl` ('' = the server needs none). */\n sttServerKey?: string;\n /** OpenAI TTS model ('' → 'tts-1'; e.g. 'gpt-4o-mini-tts'). */\n ttsModel: string;\n /** OpenRouter models ('' → the defaults of openrouter.ts) */\n openrouterSttModel: string;\n openrouterTtsModel: string;\n /** Decoder for compressed speech (OpenRouter models that only return mp3); absent → those models fail */\n decodeAudio?: AudioDecoder;\n /** Longest text that is spoken, in characters; longer ones are cut at a sentence end. 0 = no limit, absent = 400. */\n ttsMaxChars?: number;\n /**\n * Language the satellites listen in (ISO-639-1). A voice set for one language (Polly 'Vicki') is only used for\n * it; an answer in another language gets the default voice of that language.\n */\n language?: string;\n /**\n * Table \"voice per language\" (ISO code → voice and/or model of the main TTS provider); absent = the voices above.\n * A model only for OpenAI and OpenRouter, the others have no choice.\n */\n voicesByLanguage?: Record<string, LanguageVoice>;\n /** Language the answering tier reported for exactly this text (pi-agent `language`); absent → by its letters. */\n reportedLanguage?: (text: string) => string | undefined;\n /** Instance of ioBroker.voice for the provider `parakeet`, e.g. 'voice.0'. */\n parakeetInstance?: string;\n /** Message bus to other instances (voice); absent → `parakeet` cannot be used. */\n sendMessage?: MessageSender;\n}\n\nfunction requireAzure(creds: VoiceCredentials): void {\n if (!creds.azureKey || !creds.azureRegion) {\n throw new Error('Azure speech needs a subscription key and region');\n }\n}\n\nfunction requireAws(creds: VoiceCredentials): void {\n if (!creds.aws.accessKeyId || !creds.aws.secretAccessKey || !creds.aws.region) {\n throw new Error('AWS speech needs an access key id, secret access key and region');\n }\n}\n\nfunction requireOpenAi(creds: VoiceCredentials): void {\n if (!creds.openaiKey) {\n throw new Error('OpenAI speech needs an API key');\n }\n}\n\nfunction requireOpenRouter(creds: VoiceCredentials): void {\n if (!creds.openrouterKey) {\n throw new Error('OpenRouter speech needs an API key');\n }\n}\n\nexport function createSttEngine(provider: SpeechProvider, ctx: EngineContext): SttEngine {\n const primary: NamedEngine<SttEngine> = { name: provider, engine: buildSttEngine(provider, ctx) };\n const fallback = ctx.sttFallback && ctx.sttFallback !== provider ? ctx.sttFallback : '';\n if (!fallback) {\n return primary.engine;\n }\n try {\n return new FallbackStt([primary, { name: fallback, engine: buildSttEngine(fallback, ctx) }], ctx.log);\n } catch (e) {\n ctx.log.warn(`Speech-to-text fallback '${fallback}' unavailable: ${(e as Error).message}`);\n return primary.engine;\n }\n}\n\nfunction buildSttEngine(provider: SpeechProvider, ctx: EngineContext): SttEngine {\n switch (provider) {\n case 'azure':\n requireAzure(ctx.creds);\n return new AzureStt(ctx.creds.azureKey, ctx.creds.azureRegion);\n case 'aws':\n requireAws(ctx.creds);\n return new AwsStt(ctx.creds.aws);\n case 'vosk':\n return new VoskStt(ctx.dataDir, ctx.voskModel, ctx.log);\n case 'parakeet':\n if (!ctx.sendMessage) {\n throw new Error('Parakeet speech recognition is not available here');\n }\n return new ParakeetStt((ctx.parakeetInstance || '').trim(), ctx.sendMessage);\n case 'openrouter':\n requireOpenRouter(ctx.creds);\n return new OpenRouterStt(ctx.creds.openrouterKey, ctx.openrouterSttModel);\n case 'piper':\n throw new Error('Piper is a text-to-speech engine, not speech-to-text');\n default:\n if (ctx.sttBaseUrl?.trim()) {\n return new OpenAiStt(ctx.sttServerKey || '', ctx.sttModel || undefined, ctx.sttBaseUrl);\n }\n requireOpenAi(ctx.creds);\n return new OpenAiStt(ctx.creds.openaiKey, ctx.sttModel || undefined);\n }\n}\n\nexport function createTtsEngine(provider: SpeechProvider, ctx: EngineContext): TtsEngine {\n // Outermost: every text is spoken in its own language — a German voice spells a Russian answer letter by letter\n return new LanguageTts(fallbackTts(provider, ctx), ctx.reportedLanguage, ctx.log);\n}\n\nfunction fallbackTts(provider: SpeechProvider, ctx: EngineContext): TtsEngine {\n // Each engine gets the shared behaviour (disk cache, length limit, SSML) and its own cache directory,\n // so a fallback engine's voice can never be served later while the primary one is healthy again.\n const primary: NamedEngine<TtsEngine> = { name: provider, engine: withLanguageVoices(provider, ctx) };\n const fallback = ctx.ttsFallback && ctx.ttsFallback !== provider ? ctx.ttsFallback : '';\n if (!fallback) {\n return primary.engine;\n }\n try {\n return new FallbackTts([primary, { name: fallback, engine: cachedTts(fallback, ctx) }], ctx.log);\n } catch (e) {\n // A fallback that cannot even be built (missing key, wrong provider) must not take the main one down.\n ctx.log.warn(`Text-to-speech fallback '${fallback}' unavailable: ${(e as Error).message}`);\n return primary.engine;\n }\n}\n\n/** Key of a provider in {@link VoiceNames}; the speech-to-text-only providers have no voice. */\nfunction voiceKey(provider: SpeechProvider): keyof VoiceNames | '' {\n return provider === 'vosk' || provider === 'parakeet' ? '' : provider;\n}\n\n/** Providers whose TTS model can be chosen. */\nfunction hasTtsModel(provider: SpeechProvider): boolean {\n return provider === 'openai' || provider === 'openrouter';\n}\n\n/**\n * The engine context of one row of the table \"voice per language\": its voice and model instead of the ones set above.\n * Another OpenRouter model without a voice of its own gets none — the voices belong to the model, the engine then\n * takes the first one of the model for the language.\n */\nfunction rowContext(\n provider: SpeechProvider,\n key: keyof VoiceNames,\n lang: string,\n row: LanguageVoice,\n ctx: EngineContext,\n): EngineContext {\n const model = hasTtsModel(provider) ? row.model : '';\n const otherModel =\n provider === 'openrouter' && !!model && model !== (ctx.openrouterTtsModel || DEFAULT_OPENROUTER_TTS_MODEL);\n const voice = row.voice || (otherModel ? '' : ctx.voices[key]);\n return {\n ...ctx,\n // the voice of a row is for its language (Polly names say nothing about it)\n language: lang,\n voices: { ...ctx.voices, [key]: voice },\n ttsModel: provider === 'openai' && model ? model : ctx.ttsModel,\n openrouterTtsModel: provider === 'openrouter' && model ? model : ctx.openrouterTtsModel,\n };\n}\n\n/**\n * The main provider with the table \"voice per language\": one engine per row with that voice and model. The table\n * names voices and models of the main provider, so the fallback provider does not get it.\n */\nfunction withLanguageVoices(provider: SpeechProvider, ctx: EngineContext): TtsEngine {\n const main = cachedTts(provider, ctx);\n const key = voiceKey(provider);\n const rows = Object.entries(ctx.voicesByLanguage || {});\n if (!key || !rows.length) {\n return main;\n }\n const byLanguage: Record<string, TtsEngine> = {};\n for (const [lang, row] of rows) {\n if (row.model && !hasTtsModel(provider)) {\n ctx.log.warn(`TTS model '${row.model}' for '${lang}' ignored: ${provider} has no model choice`);\n if (!row.voice) {\n continue;\n }\n }\n try {\n byLanguage[lang] = cachedTts(provider, rowContext(provider, key, lang, row, ctx));\n } catch (e) {\n ctx.log.warn(`Voice '${row.voice || row.model}' for '${lang}' unavailable: ${(e as Error).message}`);\n }\n }\n return new VoicePerLanguage(main, byLanguage);\n}\n\n/**\n * One provider binding plus the shared cache/length/SSML layer. One cache directory per provider+voice —\n * a voice change must not serve audio in the old voice.\n */\nfunction cachedTts(provider: SpeechProvider, ctx: EngineContext): TtsEngine {\n const voice =\n provider === 'azure'\n ? ctx.voices.azure\n : provider === 'aws'\n ? ctx.voices.aws\n : provider === 'piper'\n ? ctx.voices.piper\n : provider === 'openrouter'\n ? `${ctx.openrouterTtsModel || DEFAULT_OPENROUTER_TTS_MODEL}-${ctx.voices.openrouter}`\n : // the model too: another model must not serve the audio of the old one\n `${ctx.ttsModel ? `${ctx.ttsModel}-` : ''}${ctx.voices.openai}`;\n const dir = path.join(ctx.dataDir, 'ttscache', `${provider}-${(voice || 'default').replace(/[^\\w.-]/g, '_')}`);\n return new CachedTts(buildTtsEngine(provider, ctx), { dir, log: ctx.log, maxChars: ctx.ttsMaxChars });\n}\n\nfunction buildTtsEngine(provider: SpeechProvider, ctx: EngineContext): TtsEngine {\n switch (provider) {\n case 'azure':\n requireAzure(ctx.creds);\n return new AzureTts(ctx.creds.azureKey, ctx.creds.azureRegion, ctx.voices.azure);\n case 'aws':\n requireAws(ctx.creds);\n return new AwsTts(ctx.creds.aws, ctx.voices.aws, ctx.language);\n case 'piper':\n return new PiperTts(ctx.dataDir, ctx.voices.piper, ctx.log);\n case 'vosk':\n throw new Error('Vosk is a speech-to-text engine, not text-to-speech');\n case 'parakeet':\n throw new Error('Parakeet is a speech-to-text engine, not text-to-speech');\n case 'openrouter':\n requireOpenRouter(ctx.creds);\n return new OpenRouterTts(\n ctx.creds.openrouterKey,\n ctx.openrouterTtsModel,\n ctx.voices.openrouter,\n ctx.decodeAudio,\n );\n default:\n requireOpenAi(ctx.creds);\n return new OpenAiTts(\n ctx.creds.openaiKey,\n (ctx.voices.openai || 'alloy') as OpenAiVoice,\n ctx.ttsModel || undefined,\n );\n }\n}\n\n/** OpenAI TTS voices are a fixed set (no list API). */\nconst OPENAI_VOICES = ['alloy', 'echo', 'fable', 'onyx', 'nova', 'shimmer'];\n\n/** List the available TTS voices for a provider (for the settings voice dropdown). */\nexport async function listVoices(provider: SpeechProvider, ctx: EngineContext, language: string): Promise<string[]> {\n switch (provider) {\n case 'azure':\n requireAzure(ctx.creds);\n return listAzureVoices(ctx.creds.azureKey, ctx.creds.azureRegion, isoToLocale(language));\n case 'aws':\n requireAws(ctx.creds);\n return listPollyVoices(ctx.creds.aws, isoToLocale(language));\n case 'piper':\n return listPiperVoices();\n case 'openrouter': {\n // public list, no key needed: the voices of the chosen model\n const model = ctx.openrouterTtsModel || DEFAULT_OPENROUTER_TTS_MODEL;\n const models = await listOpenRouterSpeechModels('speech');\n return voicesForLanguage(models.find(m => m.id === model)?.voices || [], language);\n }\n default:\n return OPENAI_VOICES;\n }\n}\n\n/** Suggested STT model names for the settings dropdown: the local Vosk catalogue, or the models of OpenRouter. */\nexport async function listSttModels(provider: SpeechProvider, language: string): Promise<string[]> {\n if (provider === 'openrouter') {\n return (await listOpenRouterSpeechModels('transcription')).map(m => m.id);\n }\n return provider === 'vosk' ? listVoskModels(language) : [];\n}\n\n/** OpenAI TTS models (no list API that tells speech models apart). */\nconst OPENAI_TTS_MODELS = ['tts-1', 'tts-1-hd', 'gpt-4o-mini-tts'];\n\n/** TTS model names for the settings dropdown; the other providers have no model choice. */\nexport async function listTtsModels(provider: SpeechProvider): Promise<string[]> {\n if (provider === 'openrouter') {\n return (await listOpenRouterSpeechModels('speech')).map(m => m.id);\n }\n return provider === 'openai' ? OPENAI_TTS_MODELS : [];\n}\n"]}
@@ -1,15 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ParakeetStt = void 0;
4
+ exports.renamedParakeetInstance = renamedParakeetInstance;
4
5
  /**
5
- * Speech recognition by the adapter ioBroker.ai-parakeet (NVIDIA Parakeet TDT 0.6B v3 on the CPU, 25 European
6
+ * Speech recognition by the adapter ioBroker.voice (NVIDIA Parakeet TDT 0.6B v3 on the CPU, 25 European
6
7
  * languages, detected automatically).
7
8
  *
8
- * Over the message bus, not over its HTTP API: `sendTo('ai-parakeet.0', 'transcribe', { pcm, sampleRate, prompt })`
9
+ * Over the message bus, not over its HTTP API: `sendTo('voice.0', 'transcribe', { pcm, sampleRate, prompt })`
9
10
  * works on any host of a multihost system without an address, and an API key set there does not matter. The PCM goes
10
11
  * as base64 — a Buffer would be serialised as a JSON array of numbers.
11
12
  */
12
13
  const stt_1 = require("./stt");
14
+ /**
15
+ * ioBroker.voice was called ai-parakeet up to its version 0.1.x. For a saved instance `ai-parakeet.<n>` this returns
16
+ * `voice.<n>`, the instance that takes over its settings; null for anything else.
17
+ */
18
+ function renamedParakeetInstance(instance) {
19
+ const match = /^(?:system\.adapter\.)?ai-parakeet\.(\d+)$/.exec(instance.trim());
20
+ return match ? `voice.${match[1]}` : null;
21
+ }
13
22
  class ParakeetStt {
14
23
  instance;
15
24
  send;
@@ -17,7 +26,7 @@ class ParakeetStt {
17
26
  this.instance = instance;
18
27
  this.send = send;
19
28
  if (!instance) {
20
- throw new Error('Parakeet speech recognition needs an ai-parakeet instance');
29
+ throw new Error('Parakeet speech recognition needs an instance of ioBroker.voice');
21
30
  }
22
31
  }
23
32
  /** `lang` is not sent: the model detects the language itself. */
@@ -1 +1 @@
1
- {"version":3,"file":"parakeet.js","sourceRoot":"","sources":["../../../src/lib/voice/parakeet.ts"],"names":[],"mappings":";;;AAAA;;;;;;;GAOG;AACH,+BAAsD;AAKtD,MAAa,WAAW;IAEC;IACA;IAFrB,YACqB,QAAgB,EAChB,IAAmB;QADnB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,SAAI,GAAJ,IAAI,CAAe;QAEpC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAC;QACjF,CAAC;IACL,CAAC;IAED,iEAAiE;IACjE,KAAK,CAAC,UAAU,CAAC,GAAW,EAAE,UAAkB,EAAE,KAAa,EAAE,KAAgB;QAC7E,MAAM,MAAM,GAAG,IAAA,mBAAa,EAAC,KAAK,CAAC,CAAC;QACpC,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,EAAE;YACzD,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAC3B,UAAU;YACV,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChC,CAAC,CAA2D,CAAC;QAC9D,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,iBAAiB,CAAC,CAAC;QACvD,CAAC;QACD,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,KAAK,GAAG,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC7F,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACrE,CAAC;CACJ;AA3BD,kCA2BC","sourcesContent":["/**\n * Speech recognition by the adapter ioBroker.ai-parakeet (NVIDIA Parakeet TDT 0.6B v3 on the CPU, 25 European\n * languages, detected automatically).\n *\n * Over the message bus, not over its HTTP API: `sendTo('ai-parakeet.0', 'transcribe', { pcm, sampleRate, prompt })`\n * works on any host of a multihost system without an address, and an API key set there does not matter. The PCM goes\n * as base64 — a Buffer would be serialised as a JSON array of numbers.\n */\nimport { hintsToPrompt, type SttEngine } from './stt';\n\n/** Sends a message to another instance and resolves with its answer; rejects when it is not running or times out. */\nexport type MessageSender = (instance: string, command: string, message: Record<string, unknown>) => Promise<unknown>;\n\nexport class ParakeetStt implements SttEngine {\n constructor(\n private readonly instance: string,\n private readonly send: MessageSender,\n ) {\n if (!instance) {\n throw new Error('Parakeet speech recognition needs an ai-parakeet instance');\n }\n }\n\n /** `lang` is not sent: the model detects the language itself. */\n async transcribe(pcm: Buffer, sampleRate: number, _lang: string, hints?: string[]): Promise<string> {\n const prompt = hintsToPrompt(hints);\n const answer = (await this.send(this.instance, 'transcribe', {\n pcm: pcm.toString('base64'),\n sampleRate,\n ...(prompt ? { prompt } : {}),\n })) as { text?: unknown; error?: unknown } | null | undefined;\n if (!answer || typeof answer !== 'object') {\n throw new Error(`${this.instance} gave no answer`);\n }\n if (answer.error) {\n const error = typeof answer.error === 'string' ? answer.error : JSON.stringify(answer.error);\n throw new Error(`${this.instance}: ${error}`);\n }\n return typeof answer.text === 'string' ? answer.text.trim() : '';\n }\n}\n"]}
1
+ {"version":3,"file":"parakeet.js","sourceRoot":"","sources":["../../../src/lib/voice/parakeet.ts"],"names":[],"mappings":";;;AAcA,0DAGC;AAjBD;;;;;;;GAOG;AACH,+BAAsD;AAEtD;;;GAGG;AACH,SAAgB,uBAAuB,CAAC,QAAgB;IACpD,MAAM,KAAK,GAAG,4CAA4C,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;IACjF,OAAO,KAAK,CAAC,CAAC,CAAC,SAAS,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC9C,CAAC;AAKD,MAAa,WAAW;IAEC;IACA;IAFrB,YACqB,QAAgB,EAChB,IAAmB;QADnB,aAAQ,GAAR,QAAQ,CAAQ;QAChB,SAAI,GAAJ,IAAI,CAAe;QAEpC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,iEAAiE,CAAC,CAAC;QACvF,CAAC;IACL,CAAC;IAED,iEAAiE;IACjE,KAAK,CAAC,UAAU,CAAC,GAAW,EAAE,UAAkB,EAAE,KAAa,EAAE,KAAgB;QAC7E,MAAM,MAAM,GAAG,IAAA,mBAAa,EAAC,KAAK,CAAC,CAAC;QACpC,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,EAAE;YACzD,GAAG,EAAE,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC;YAC3B,UAAU;YACV,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SAChC,CAAC,CAA2D,CAAC;QAC9D,IAAI,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;YACxC,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,iBAAiB,CAAC,CAAC;QACvD,CAAC;QACD,IAAI,MAAM,CAAC,KAAK,EAAE,CAAC;YACf,MAAM,KAAK,GAAG,OAAO,MAAM,CAAC,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAC7F,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,QAAQ,KAAK,KAAK,EAAE,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACrE,CAAC;CACJ;AA3BD,kCA2BC","sourcesContent":["/**\n * Speech recognition by the adapter ioBroker.voice (NVIDIA Parakeet TDT 0.6B v3 on the CPU, 25 European\n * languages, detected automatically).\n *\n * Over the message bus, not over its HTTP API: `sendTo('voice.0', 'transcribe', { pcm, sampleRate, prompt })`\n * works on any host of a multihost system without an address, and an API key set there does not matter. The PCM goes\n * as base64 — a Buffer would be serialised as a JSON array of numbers.\n */\nimport { hintsToPrompt, type SttEngine } from './stt';\n\n/**\n * ioBroker.voice was called ai-parakeet up to its version 0.1.x. For a saved instance `ai-parakeet.<n>` this returns\n * `voice.<n>`, the instance that takes over its settings; null for anything else.\n */\nexport function renamedParakeetInstance(instance: string): string | null {\n const match = /^(?:system\\.adapter\\.)?ai-parakeet\\.(\\d+)$/.exec(instance.trim());\n return match ? `voice.${match[1]}` : null;\n}\n\n/** Sends a message to another instance and resolves with its answer; rejects when it is not running or times out. */\nexport type MessageSender = (instance: string, command: string, message: Record<string, unknown>) => Promise<unknown>;\n\nexport class ParakeetStt implements SttEngine {\n constructor(\n private readonly instance: string,\n private readonly send: MessageSender,\n ) {\n if (!instance) {\n throw new Error('Parakeet speech recognition needs an instance of ioBroker.voice');\n }\n }\n\n /** `lang` is not sent: the model detects the language itself. */\n async transcribe(pcm: Buffer, sampleRate: number, _lang: string, hints?: string[]): Promise<string> {\n const prompt = hintsToPrompt(hints);\n const answer = (await this.send(this.instance, 'transcribe', {\n pcm: pcm.toString('base64'),\n sampleRate,\n ...(prompt ? { prompt } : {}),\n })) as { text?: unknown; error?: unknown } | null | undefined;\n if (!answer || typeof answer !== 'object') {\n throw new Error(`${this.instance} gave no answer`);\n }\n if (answer.error) {\n const error = typeof answer.error === 'string' ? answer.error : JSON.stringify(answer.error);\n throw new Error(`${this.instance}: ${error}`);\n }\n return typeof answer.text === 'string' ? answer.text.trim() : '';\n }\n}\n"]}
package/build/main.js CHANGED
@@ -56,6 +56,7 @@ const llmBenchmark_1 = require("./lib/llmBenchmark");
56
56
  const credentials_1 = require("./lib/credentials");
57
57
  const context_1 = require("./lib/context");
58
58
  const ask_1 = require("./lib/ask");
59
+ const messages_1 = require("./lib/messages");
59
60
  const presence_1 = require("./lib/presence");
60
61
  const targets_1 = require("./lib/targets");
61
62
  const routines_1 = require("./lib/routines");
@@ -72,6 +73,7 @@ const wakeWords_1 = require("./lib/voice/wakeWords");
72
73
  const tone_1 = require("./lib/voice/tone");
73
74
  const engines_1 = require("./lib/voice/engines");
74
75
  const openrouter_1 = require("./lib/voice/openrouter");
76
+ const parakeet_1 = require("./lib/voice/parakeet");
75
77
  const ttsCache_1 = require("./lib/voice/ttsCache");
76
78
  const captures_1 = require("./lib/voice/captures");
77
79
  const ffmpegStatic_1 = require("./lib/voice/ffmpegStatic");
@@ -154,12 +156,12 @@ const VOICE_FORM_SECRETS = [
154
156
  'awsSecretAccessKey',
155
157
  'sttServerKey',
156
158
  ];
157
- /** How long ai-parakeet may take for one recognition (queue, loading an unloaded model, a slow host). */
159
+ /** How long ioBroker.voice may take for one recognition (queue, loading an unloaded model, a slow host). */
158
160
  const PARAKEET_TIMEOUT_MS = 60_000;
159
161
  /** Adapters a button in the settings installs, and the setting that gets their instance. */
160
162
  const HELPER_ADAPTERS = new Map([
161
163
  ['pi-agent', 'piAgentInstance'],
162
- ['ai-parakeet', 'parakeetInstance'],
164
+ ['voice', 'parakeetInstance'],
163
165
  ]);
164
166
  /** An empty `ask` from the same caller is reported at most this often. */
165
167
  const EMPTY_ASK_REPORT_MS = 60_000;
@@ -318,7 +320,7 @@ class Assistant extends adapter_core_1.Adapter {
318
320
  agent = null;
319
321
  /** Provider "pi-agent": the cloud tier is a pi-agent instance instead of {@link agent}. */
320
322
  piAgent = null;
321
- /** Installs pi-agent / ai-parakeet from the settings; created on the first use. */
323
+ /** Installs pi-agent / voice from the settings; created on the first use. */
322
324
  installer = null;
323
325
  /** The cloud LLM of the instance (own or system-wide settings); `null` without one. */
324
326
  llm = null;
@@ -434,7 +436,36 @@ class Assistant extends adapter_core_1.Adapter {
434
436
  this.on('message', this.onMessage.bind(this));
435
437
  this.on('unload', this.onUnload.bind(this));
436
438
  }
439
+ /**
440
+ * ioBroker.voice was called ai-parakeet up to its 0.1.x. Once its instance `voice.<n>` exists, the setting
441
+ * `ai-parakeet.<n>` moves to it; the instance then restarts. True if it was changed.
442
+ */
443
+ async followRenamedParakeet() {
444
+ const next = (0, parakeet_1.renamedParakeetInstance)(this.config.parakeetInstance || '');
445
+ if (!next) {
446
+ return false;
447
+ }
448
+ try {
449
+ const target = await this.getForeignObjectAsync(`system.adapter.${next}`);
450
+ if (!target) {
451
+ return false;
452
+ }
453
+ this.log.info(`ai-parakeet was renamed to voice: the speech recognition now uses ${next} instead of ${this.config.parakeetInstance}`);
454
+ await this.extendForeignObjectAsync(`system.adapter.${this.namespace}`, {
455
+ native: { parakeetInstance: next },
456
+ });
457
+ return true;
458
+ }
459
+ catch (e) {
460
+ this.log.warn(`Could not switch the speech recognition to ${next}: ${e.message}`);
461
+ return false;
462
+ }
463
+ }
437
464
  async onReady() {
465
+ if (await this.followRenamedParakeet()) {
466
+ // The instance restarts with the new setting.
467
+ return;
468
+ }
438
469
  const cfg = this.config;
439
470
  // Provider "none": no cloud LLM at all — only the local tiers (routines, rule-based NLU, timers,
440
471
  // alarms, the local model) answer. The ioBroker tools are still built: the NLU switches through them.
@@ -2659,7 +2690,13 @@ class Assistant extends adapter_core_1.Adapter {
2659
2690
  if (!obj?.command) {
2660
2691
  return;
2661
2692
  }
2662
- // Output of a command the host runs for us (installing pi-agent / ai-parakeet).
2693
+ // A reply whose callback is gone (we restarted while the other adapter answered) is no request: answering it
2694
+ // would send it back, and a caller that does the same keeps both adapters in a loop.
2695
+ if ((0, messages_1.isLateReply)(obj)) {
2696
+ this.log.debug(`Ignoring a late reply from ${obj.from} to "${obj.command}"`);
2697
+ return;
2698
+ }
2699
+ // Output of a command the host runs for us (installing pi-agent / voice).
2663
2700
  if (this.installer?.handleMessage(obj.command, obj.message)) {
2664
2701
  return;
2665
2702
  }
@@ -2667,7 +2704,7 @@ class Assistant extends adapter_core_1.Adapter {
2667
2704
  if (await this.handleLocalModelMessage(obj)) {
2668
2705
  return;
2669
2706
  }
2670
- // Settings buttons "Install pi-agent" / "Install ai-parakeet".
2707
+ // Settings buttons "Install pi-agent" / "Install ioBroker.voice".
2671
2708
  if (obj.command === 'installAdapter') {
2672
2709
  const result = await this.installHelperAdapter(obj.message);
2673
2710
  if (obj.callback) {
@@ -4835,7 +4872,7 @@ class Assistant extends adapter_core_1.Adapter {
4835
4872
  return this.sendToAsync(instance, command, message, { timeout: timeoutMs });
4836
4873
  }
4837
4874
  /**
4838
- * Settings button: install pi-agent or ai-parakeet on this host if needed, create an instance if there is
4875
+ * Settings button: install pi-agent or voice on this host if needed, create an instance if there is
4839
4876
  * none, and put it into the form (`native`). Takes minutes on a Raspberry Pi; the log shows the steps.
4840
4877
  */
4841
4878
  async installHelperAdapter(message) {