ニジカ投稿局 https://tv.nizika.tv
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

transcriber-factory.ts 1.2 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { SimpleLogger } from '@peertube/peertube-models'
  2. import { TranscriptionEngine, TranscriptionEngineName } from './transcription-engine.js'
  3. import { Ctranslate2Transcriber, OpenaiTranscriber } from './whisper/index.js'
  4. export class TranscriberFactory {
  5. engines: TranscriptionEngine[]
  6. constructor (engines: TranscriptionEngine[]) {
  7. this.engines = engines
  8. }
  9. createFromEngineName (options: {
  10. engineName: TranscriptionEngineName
  11. enginePath?: string
  12. binDirectory?: string
  13. logger: SimpleLogger
  14. }) {
  15. const { engineName } = options
  16. const transcriberArgs = {
  17. ...options,
  18. engine: this.getEngineByName(engineName)
  19. }
  20. switch (engineName) {
  21. case 'openai-whisper':
  22. return new OpenaiTranscriber(transcriberArgs)
  23. case 'whisper-ctranslate2':
  24. return new Ctranslate2Transcriber(transcriberArgs)
  25. default:
  26. throw new Error(`Unimplemented engine ${engineName}`)
  27. }
  28. }
  29. getEngineByName (engineName: string) {
  30. const engine = this.engines.find(({ name }) => name === engineName)
  31. if (!engine) {
  32. throw new Error(`Unknow engine ${engineName}`)
  33. }
  34. return engine
  35. }
  36. }