代码示例 / Node / PHP

nodejs 基础对话


npm i openai


const fs = require('fs');

const OpenAI = require('openai');



const openai = new OpenAI({

  apiKey: 'sk-xxxxxxxx', 

  baseURL: 'https://www.cokeapi.com/v1'

});



async function transcribeAudio() {

  try {

    const transcription = await openai.audio.transcriptions.create({

      file: fs.createReadStream('a-product-demo-167264.mp3'), // 替换为你的音频文件路径

      model: 'whisper-1', 

    });



    console.log('转录结果:', transcription.text);

  } catch (error) {

    console.error('转录出错:', error);

  }

}



transcribeAudio();