diff --git a/packages/bot-services/CLAUDE.md b/packages/bot-services/CLAUDE.md index ea18337c1..1cd6266ae 100644 --- a/packages/bot-services/CLAUDE.md +++ b/packages/bot-services/CLAUDE.md @@ -124,7 +124,18 @@ const convId = sessionService.getSessionData('@user:matrix.org', 'curren ### Transcription Service (Speech-to-Text) ```typescript -import { TranscriptionService } from '@manacore/bot-services'; +import { TranscriptionService, TranscriptionModule } from '@manacore/bot-services'; + +// Module registration with API key +TranscriptionModule.register({ + sttUrl: 'http://mana-stt:3020', + apiKey: process.env.STT_API_KEY, // Optional: for authenticated STT service + defaultLanguage: 'de' +}) + +// Or use forRoot() which reads from config: +// - stt.url / STT_URL +// - stt.apiKey / STT_API_KEY // Transcribe audio buffer const text = await transcriptionService.transcribe(audioBuffer, { language: 'de' }); diff --git a/packages/bot-services/src/transcription/transcription.service.ts b/packages/bot-services/src/transcription/transcription.service.ts index 6db7237b9..5a0b9f2b9 100644 --- a/packages/bot-services/src/transcription/transcription.service.ts +++ b/packages/bot-services/src/transcription/transcription.service.ts @@ -27,6 +27,7 @@ export class TranscriptionService { private readonly logger = new Logger(TranscriptionService.name); private readonly sttUrl: string; private readonly defaultLanguage: string; + private readonly apiKey: string; constructor( @Optional() private configService: ConfigService, @@ -41,6 +42,12 @@ export class TranscriptionService { this.defaultLanguage = options?.defaultLanguage || 'de'; + this.apiKey = + options?.apiKey || + this.configService?.get('stt.apiKey') || + this.configService?.get('STT_API_KEY') || + ''; + this.logger.log(`STT Service URL: ${this.sttUrl}`); } @@ -64,8 +71,14 @@ export class TranscriptionService { } try { + const headers: Record = {}; + if (this.apiKey) { + headers['X-API-Key'] = this.apiKey; + } + const response = await fetch(`${this.sttUrl}/transcribe`, { method: 'POST', + headers, body: formData, }); @@ -102,8 +115,14 @@ export class TranscriptionService { } try { + const headers: Record = {}; + if (this.apiKey) { + headers['X-API-Key'] = this.apiKey; + } + const response = await fetch(`${this.sttUrl}/transcribe`, { method: 'POST', + headers, body: formData, }); @@ -124,7 +143,12 @@ export class TranscriptionService { */ async checkHealth(): Promise { try { - const response = await fetch(`${this.sttUrl}/health`); + const headers: Record = {}; + if (this.apiKey) { + headers['X-API-Key'] = this.apiKey; + } + + const response = await fetch(`${this.sttUrl}/health`, { headers }); return response.ok; } catch { return false; diff --git a/packages/bot-services/src/transcription/types.ts b/packages/bot-services/src/transcription/types.ts index 58c4d4565..b33cdea82 100644 --- a/packages/bot-services/src/transcription/types.ts +++ b/packages/bot-services/src/transcription/types.ts @@ -17,6 +17,7 @@ export interface TranscriptionOptions { export interface TranscriptionModuleOptions { sttUrl?: string; defaultLanguage?: string; + apiKey?: string; } export const STT_MODULE_OPTIONS = 'STT_MODULE_OPTIONS';