dify/e2e/support/test-materials.ts
yyh ab521c4cfd
refactor(chat): modernize speech-to-text pipeline (#38653)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: Yansong Zhang <916125788@qq.com>
2026-07-13 04:21:29 +00:00

41 lines
1.2 KiB
TypeScript

import { Buffer } from 'node:buffer'
import { mkdir, writeFile } from 'node:fs/promises'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
export const testMaterialsDir = fileURLToPath(
new URL('../fixtures/test-materials', import.meta.url),
)
export const generatedTestMaterialsDir = fileURLToPath(
new URL('../.generated-test-materials', import.meta.url),
)
export const voiceInputTestMaterial = {
fileName: 'voice-input.wav',
recordingDuration: '00:07',
} as const
export const getTestMaterialPath = (fileName: string) => path.join(testMaterialsDir, fileName)
export const getVoiceInputTestMaterialPath = () =>
getTestMaterialPath(voiceInputTestMaterial.fileName)
export async function getGeneratedTextMaterialPath({
fileName,
sizeBytes,
seedText,
}: {
fileName: string
sizeBytes: number
seedText: string
}) {
await mkdir(generatedTestMaterialsDir, { recursive: true })
const targetPath = path.join(generatedTestMaterialsDir, fileName)
const chunk = `${seedText}\n`
const repeatCount = Math.ceil(sizeBytes / Buffer.byteLength(chunk))
const contents = chunk.repeat(repeatCount).slice(0, sizeBytes)
await writeFile(targetPath, contents)
return targetPath
}