feat(#389): create SpeechModule with provider abstraction layer
All checks were successful
ci/woodpecker/push/api Pipeline was successful
All checks were successful
ci/woodpecker/push/api Pipeline was successful
Add SpeechModule with provider interfaces and service skeleton for multi-tier TTS fallback (premium -> default -> fallback) and STT transcription support. Includes 27 unit tests covering provider selection, fallback logic, and availability checks. - ISTTProvider interface with transcribe/isHealthy methods - ITTSProvider interface with synthesize/listVoices/isHealthy methods - Shared types: SpeechTier, TranscriptionResult, SynthesisResult, etc. - SpeechService with graceful TTS fallback chain - NestJS injection tokens (STT_PROVIDER, TTS_PROVIDERS) - SpeechModule registered in AppModule - ConfigModule integration via speechConfig registerAs factory Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
49
apps/api/src/speech/speech.module.ts
Normal file
49
apps/api/src/speech/speech.module.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* SpeechModule
|
||||
*
|
||||
* NestJS module for speech-to-text (STT) and text-to-speech (TTS) services.
|
||||
* Provides a provider abstraction layer with graceful fallback for TTS tiers.
|
||||
*
|
||||
* Imports:
|
||||
* - ConfigModule.forFeature(speechConfig) for speech configuration
|
||||
*
|
||||
* Providers:
|
||||
* - SpeechService: High-level speech operations with provider selection
|
||||
* - TTS_PROVIDERS: Empty Map<SpeechTier, ITTSProvider> (populated by provider modules)
|
||||
*
|
||||
* Exports:
|
||||
* - SpeechService for use by other modules (e.g., controllers, brain)
|
||||
*
|
||||
* Issue #389
|
||||
*/
|
||||
|
||||
import { Module, type OnModuleInit, Logger } from "@nestjs/common";
|
||||
import { ConfigModule } from "@nestjs/config";
|
||||
import { speechConfig, validateSpeechConfig } from "./speech.config";
|
||||
import { SpeechService } from "./speech.service";
|
||||
import { TTS_PROVIDERS } from "./speech.constants";
|
||||
import type { SpeechTier } from "./interfaces/speech-types";
|
||||
import type { ITTSProvider } from "./interfaces/tts-provider.interface";
|
||||
|
||||
@Module({
|
||||
imports: [ConfigModule.forFeature(speechConfig)],
|
||||
providers: [
|
||||
SpeechService,
|
||||
// Default empty TTS providers map. Provider modules (Kokoro, Chatterbox, etc.)
|
||||
// will register their providers in subsequent tasks.
|
||||
{
|
||||
provide: TTS_PROVIDERS,
|
||||
useFactory: (): Map<SpeechTier, ITTSProvider> => new Map(),
|
||||
},
|
||||
],
|
||||
exports: [SpeechService],
|
||||
})
|
||||
export class SpeechModule implements OnModuleInit {
|
||||
private readonly logger = new Logger(SpeechModule.name);
|
||||
|
||||
onModuleInit(): void {
|
||||
// Validate configuration at startup (fail fast)
|
||||
validateSpeechConfig();
|
||||
this.logger.log("Speech module initialized");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user