mirror of
https://github.com/penxio/penx.git
synced 2026-01-12 23:18:09 -05:00
31 lines
699 B
TypeScript
31 lines
699 B
TypeScript
import fs from 'fs'
|
|
import OpenAI from 'openai'
|
|
|
|
const openai = new OpenAI({
|
|
// apiKey: process.env.OPENAI_API_KEY,
|
|
baseURL: 'https://api.laozhang.ai/v1',
|
|
apiKey: 'sk-YtcaDM3AN4yINYd03d57214035Aa4bA0AcA0E408290fEa0e',
|
|
})
|
|
|
|
const filePath = '/Users/ziyi/Desktop/test.m4a'
|
|
|
|
async function init() {
|
|
const fileStream = fs.createReadStream(filePath)
|
|
|
|
try {
|
|
const transcription = await openai.audio.transcriptions.create({
|
|
model: 'gpt-4o-transcribe',
|
|
file: fileStream,
|
|
response_format: 'text',
|
|
// language: 'zh',
|
|
temperature: 0.2,
|
|
})
|
|
|
|
console.log('-------transcription:', transcription)
|
|
} catch (error) {
|
|
console.log('error:', error)
|
|
}
|
|
}
|
|
|
|
init()
|