Skip to content

Commit

Permalink
chore(transcription): make fromPath method async
Browse files Browse the repository at this point in the history
  • Loading branch information
lutangar committed May 31, 2024
1 parent 0ccf064 commit 57b9055
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('Open AI Whisper transcriber', function () {
this.timeout(3 * 1000 * 60)
await transcriber.transcribe({
mediaFilePath: frVideoPath,
model: TranscriptionModel.fromPath(buildAbsoluteFixturePath('transcription/models/tiny.pt')),
model: await TranscriptionModel.fromPath(buildAbsoluteFixturePath('transcription/models/tiny.pt')),
language: 'en'
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ describe('Linto timestamped Whisper transcriber', function () {

it('May transcribe a media file using a local PyTorch model file', async function () {
this.timeout(2 * 1000 * 60)
await transcriber.transcribe({ mediaFilePath: frVideoPath, model: TranscriptionModel.fromPath(buildAbsoluteFixturePath('transcription/models/tiny.pt')), language: 'en' })
await transcriber.transcribe({
mediaFilePath: frVideoPath,
model: await TranscriptionModel.fromPath(buildAbsoluteFixturePath('transcription/models/tiny.pt')),
language: 'en'
})
})

it('May transcribe a media file in french', async function () {
Expand All @@ -93,7 +97,7 @@ describe('Linto timestamped Whisper transcriber', function () {
this.timeout(5 * 1000 * 60)
const transcribeArgs: WhisperTranscribeArgs = {
mediaFilePath: frVideoPath,
model: TranscriptionModel.fromPath(buildAbsoluteFixturePath('transcription/models/tiny.pt')),
model: await TranscriptionModel.fromPath(buildAbsoluteFixturePath('transcription/models/tiny.pt')),
language: 'fr',
format: 'txt'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ describe('Whisper CTranslate2 transcriber', function () {
this.timeout(2 * 1000 * 60)
const transcript = await transcriber.transcribe({
mediaFilePath: shortVideoPath,
model: TranscriptionModel.fromPath(buildAbsoluteFixturePath('transcription/models/faster-whisper-tiny')),
model: await TranscriptionModel.fromPath(buildAbsoluteFixturePath('transcription/models/faster-whisper-tiny')),
language: 'en',
format: 'txt'
})
Expand Down Expand Up @@ -104,7 +104,7 @@ describe('Whisper CTranslate2 transcriber', function () {
this.timeout(5 * 1000 * 60)
const transcribeArgs: WhisperTranscribeArgs = {
mediaFilePath: frVideoPath,
model: TranscriptionModel.fromPath(buildAbsoluteFixturePath('transcription/models/tiny.pt')),
model: await TranscriptionModel.fromPath(buildAbsoluteFixturePath('transcription/models/tiny.pt')),
language: 'fr',
format: 'txt'
}
Expand Down
6 changes: 3 additions & 3 deletions packages/transcription/src/transcription-model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'node:assert'
import { existsSync } from 'node:fs'
import { stat } from 'node:fs/promises'
import { parse } from 'node:path'

export type ModelFormat = 'PyTorch' | 'GGML' | 'ONNX' | 'CTranslate2' // CoreML, OpenVino, Scikit-Learn, TensorFlow/Keras, PySpark
Expand All @@ -26,8 +26,8 @@ export class TranscriptionModel {
this.format = format
}

static fromPath (path: string) {
assert(existsSync(path), `${path} doesn't exist.`)
static async fromPath (path: string) {
assert(await stat(path), `${path} doesn't exist.`)

return new TranscriptionModel(parse(path).name, path)
}
Expand Down

0 comments on commit 57b9055

Please sign in to comment.