Skip to content

Instantly share code, notes, and snippets.

@Trkrkrl
Created December 16, 2024 06:46
Show Gist options
  • Save Trkrkrl/87c2b24f8a196447d0ae2719b0d63f0d to your computer and use it in GitHub Desktop.
Save Trkrkrl/87c2b24f8a196447d0ae2719b0d63f0d to your computer and use it in GitHub Desktop.
import fs from "fs";
import path from "path";
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: "", // Buraya API anahtarını ekle
});
// Çevirmek istediğin metni buraya yaz
const textToConvert = " İşte buraya dönüştürülmesini istediğiniz metni yazın";
// Ses dosyasının kaydedileceği yol
const speechFile = path.resolve("./speech2.mp3");
//Dikkatli ol - Her 1000 karakter 1,5 cent
async function main() {
try {
const mp3 = await openai.audio.speech.create({
model: "tts-1-hd", // Text-to-speech model
voice: "shimmer", // Ses tonu (isteğe göre değiştirilebilir)
input: textToConvert, // Çevrilecek metin
});
// Ses dosyasını oluştur ve kaydet
const buffer = Buffer.from(await mp3.arrayBuffer());
await fs.promises.writeFile(speechFile, buffer);
console.log(`Ses dosyası başarıyla oluşturuldu: ${speechFile}`);
} catch (error) {
console.error("Bir hata oluştu:", error);
}
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment