Skip to content

Commit

Permalink
chore(transcription): use os tm directory where relevant
Browse files Browse the repository at this point in the history
  • Loading branch information
lutangar committed May 16, 2024
1 parent 70f68b9 commit 64d74c2
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 25 deletions.
11 changes: 3 additions & 8 deletions packages/tests/src/transcription/benchmark.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createLogger } from 'winston'
import { join } from 'node:path'
import { performance, PerformanceObserver } from 'node:perf_hooks'
// import { CpuInfo, CpuUsage } from 'node:os'
import { tmpdir } from 'node:os'
import { rm, mkdir } from 'node:fs/promises'
import { buildAbsoluteFixturePath, buildSUUID, SUUID } from '@peertube/peertube-node-utils'
import {
Expand All @@ -19,12 +20,6 @@ interface TestResult {
duration?: number
engine?: TranscriptionEngine
model?: string
// dataThroughput: number // relevant ?
// cpus: CpuInfo[] // https://nodejs.org/docs/latest-v18.x/api/os.html#oscpus
// cpuUsages: CpuUsage[] // https://nodejs.org/docs/latest-v18.x/api/process.html#processcpuusagepreviousvalue
// // os.totalmem()
// // os.freemem()
// memoryUsages: Record<number, MemoryUsage> // https://nodejs.org/docs/latest-v18.x/api/process.html#processmemoryusage
}

type Benchmark = Record<SUUID, TestResult>
Expand Down Expand Up @@ -64,7 +59,7 @@ describe('Transcribers benchmark', function () {
'small'
]

const transcriptDirectory = buildAbsoluteFixturePath('transcription/benchmark/')
const transcriptDirectory = join(tmpdir(), 'peertube-transcription/benchmark/')
const mediaFilePath = buildAbsoluteFixturePath('transcription/videos/derive_sectaire.mp4')
const referenceTranscriptFile = new TranscriptFile({
path: buildAbsoluteFixturePath('transcription/videos/derive_sectaire.txt'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
/* eslint-disable @typescript-eslint/no-unused-expressions, no-new, max-len */
import { TranscriptFile, TranscriptFileEvaluator } from '@peertube/peertube-transcription'
import { buildAbsoluteFixturePath } from '@peertube/peertube-node-utils'
import { join } from 'path'
import { join } from 'node:path'
import { mkdir, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { expect } from 'chai'

describe('Transcript File Evaluator', function () {
const transcriptDirectory = buildAbsoluteFixturePath('transcription/transcript-evaluator')
const referenceTranscriptFilePath = buildAbsoluteFixturePath('transcription/transcript/reference.txt')
const transcriptDirectory = join(tmpdir(), 'peertube-transcription/transcript-file-evaluator')
const referenceTranscriptFilePath = buildAbsoluteFixturePath('transcription/videos/communiquer-lors-dune-classe-transplantee.txt')

before(async function () {
await mkdir(transcriptDirectory, { recursive: true })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
/* eslint-disable @typescript-eslint/no-unused-expressions */
import { expect } from 'chai'
import { mkdir } from 'node:fs/promises'
import { join } from 'node:path'
import { mkdir, rm } from 'node:fs/promises'
import { TranscriptFile } from '@peertube/peertube-transcription'
import { buildAbsoluteFixturePath } from '@peertube/peertube-node-utils'
import { tmpdir } from 'node:os'

describe('Transcript File', function () {
const transcriptFileDirectory = join(tmpdir(), 'peertube-transcription/transcript-file/')
before(async function () {
await mkdir(buildAbsoluteFixturePath('transcription/transcript/'), { recursive: true })
await mkdir(transcriptFileDirectory, { recursive: true })
})

it(`may creates a new transcript file from scratch`, async function () {
const transcript1 = await TranscriptFile.write({
path: buildAbsoluteFixturePath('transcription/transcript/test1.txt'),
path: join(transcriptFileDirectory, 'test1.txt'),
content: 'test2',
format: 'txt'
})
const transcript2 = await TranscriptFile.write({
path: buildAbsoluteFixturePath('transcription/transcript/test2.txt'),
path: join(transcriptFileDirectory, 'test2.txt'),
content: 'test2',
format: 'txt'
})

expect(await transcript1.equals(transcript2)).to.be.true
})

after(async function () {
await rm(transcriptFileDirectory, { recursive: true, force: true })
})
})
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable @typescript-eslint/no-unused-expressions, max-len */
import { expect, config } from 'chai'
import { createLogger } from 'winston'
import { join } from 'path'
import { join } from 'node:path'
import { mkdir, rm } from 'node:fs/promises'
import { buildAbsoluteFixturePath, root } from '@peertube/peertube-node-utils'
import { tmpdir } from 'node:os'
import { buildAbsoluteFixturePath } from '@peertube/peertube-node-utils'
import {
OpenaiTranscriber,
TranscriptFile,
Expand All @@ -15,7 +16,7 @@ import {
config.truncateThreshold = 0

describe('Open AI Whisper transcriber', function () {
const transcriptDirectory = join(root(), 'test-transcript')
const transcriptDirectory = join(tmpdir(), 'peertube-transcription/transcriber/')
const shortVideoPath = buildAbsoluteFixturePath('transcription/videos/the_last_man_on_earth.mp4')
const frVideoPath = buildAbsoluteFixturePath('transcription/videos/derive_sectaire.mp4')
const referenceTranscriptFile = new TranscriptFile({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable @typescript-eslint/no-unused-expressions, max-len */
import { expect, config } from 'chai'
import { createLogger } from 'winston'
import { join } from 'path'
import { join } from 'node:path'
import { mkdir, rm } from 'node:fs/promises'
import { buildAbsoluteFixturePath, root } from '@peertube/peertube-node-utils'
import { tmpdir } from 'node:os'
import { buildAbsoluteFixturePath } from '@peertube/peertube-node-utils'
import {
OpenaiTranscriber,
WhisperTimestampedTranscriber,
Expand All @@ -17,7 +18,7 @@ import {
config.truncateThreshold = 0

describe('Linto timestamped Whisper transcriber', function () {
const transcriptDirectory = join(root(), 'test-transcript')
const transcriptDirectory = join(tmpdir(), 'peertube-transcription/transcriber')
const shortVideoPath = buildAbsoluteFixturePath('transcription/videos/the_last_man_on_earth.mp4')
const frVideoPath = buildAbsoluteFixturePath('transcription/videos/derive_sectaire.mp4')
const transcriber = new WhisperTimestampedTranscriber(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* eslint-disable @typescript-eslint/no-unused-expressions, max-len */
import { expect, config } from 'chai'
import { createLogger } from 'winston'
import { join } from 'path'
import { join } from 'node:path'
import { mkdir, readFile, rm } from 'node:fs/promises'
import { buildAbsoluteFixturePath, root } from '@peertube/peertube-node-utils'
import { tmpdir } from 'node:os'
import { buildAbsoluteFixturePath } from '@peertube/peertube-node-utils'
import {
Ctranslate2Transcriber,
OpenaiTranscriber,
Expand All @@ -15,7 +16,7 @@ import {
config.truncateThreshold = 0

describe('Whisper CTranslate2 transcriber', function () {
const transcriptDirectory = join(root(), 'test-transcript')
const transcriptDirectory = join(tmpdir(), 'peertube-transcription/transcriber/')
const shortVideoPath = buildAbsoluteFixturePath('transcription/videos/the_last_man_on_earth.mp4')
const frVideoPath = buildAbsoluteFixturePath('transcription/videos/derive_sectaire.mp4')
const transcriber = new Ctranslate2Transcriber(
Expand Down

0 comments on commit 64d74c2

Please sign in to comment.