import { app } from '../..' ; import { VoiceProvider } from './VoiceProvider' ; export type VoiceOptions = { device ? : string ; options ? : string [ ] ; } ; export const ID = { APP_NAME : '{app_name}' , PLAYBACK_DEVICE : '{playback_device}' , PLAYBACK_OPTIONS : '{playback_options}' , RECORD_DEVICE : '{record_device}' , RECORD_OPTIONS : '{record_options}' , } as const ; export const S16LE_OPTIONS = [ '-f' , 's16le' , '-ar' , '48000' , '-ac' , '2' ] ; export const flat = ( arr ) => arr . reduce ( ( a , v ) => a . concat ( v ) , [ ] ) ; let device = 'default' ; function getPlaybackDevice ( provider , opts ) { const settings = app . config . get ( 'voiceSettings' ) ; return opts . device ?? settings . outputDevice ?? provider . PLAYBACK_DEFAULT_DEVICE ; } function getRecordDevice ( provider , opts ) { const settings = app . config . get ( 'voiceSettings' ) ; return opts . device ?? settings . inputDevice ?? provider . RECORD_DEFAULT_DEVICE ; } param provider param opts param value export function process ( provider , opts , value ) { const settings = app . config . get ( 'voiceSettings' ) ; switch ( value ) { case ID . APP_NAME : return app . name ; case ID . PLAYBACK_OPTIONS : return opts . options ?? settings . playbackOptions ?? [ ] ; case ID . RECORD_OPTIONS : return opts . options ?? settings . recordOptions ?? [ ] ; default : } if ( value . includes ( ID . PLAYBACK_DEVICE ) ) { device = getPlaybackDevice ( provider , opts ) ; return value . replace ( ID . PLAYBACK_DEVICE , device ) ; } if ( value . includes ( ID . RECORD_DEVICE ) ) { device = getRecordDevice ( provider , opts ) ; return value . replace ( ID . RECORD_DEVICE , device ) ; } return value ; } param provider param options param cmdArgs export function processArgs ( provider , options , cmdArgs ) { return { args : flat ( cmdArgs . map ( ( value ) => process ( provider , options , value ) ) ) , device , } ; }