Last active
March 21, 2024 21:53
-
-
Save adainrivers/664d4f7b877a62580ad8870acbfe672b to your computer and use it in GitHub Desktop.
A simple Bun script to transcribe audio to text with a cleanup step using OpenAI Api.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import OpenAI from "openai"; | |
const openai = new OpenAI({ | |
apiKey: Bun.env.OPENAI_API_KEY | |
}); | |
var filename = "name_of_audio_file_without_extension"; | |
const mp3: any = Bun.file(`${filename}.mp3`); | |
const transcription = await openai.audio.transcriptions.create({ | |
file: mp3, | |
model: "whisper-1", | |
}); | |
const response = await openai.chat.completions.create({ | |
model: "gpt-3.5-turbo-0125", | |
messages: [ | |
{ | |
role: "system", | |
content: "Format the prompted text into logical paragraphs" | |
}, | |
{ | |
role: "user", | |
content: transcription.text | |
} | |
] | |
}); | |
await Bun.write(`${filename}.txt`, response.choices[0].message.content || ""); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment