refactor: use bun spawn for mp3 conversion
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
import fs from "fs";
|
import fs from "fs";
|
||||||
import path from "path";
|
import path from "path";
|
||||||
import ffmpeg from "fluent-ffmpeg";
|
import ffmpeg from "fluent-static";
|
||||||
|
|
||||||
// VOICEVOX APIの設定
|
// VOICEVOX APIの設定
|
||||||
const VOICEVOX_HOST = import.meta.env["VOICEVOX_HOST"];
|
const VOICEVOX_HOST = import.meta.env["VOICEVOX_HOST"];
|
||||||
@ -70,20 +70,17 @@ export async function generateTTS(
|
|||||||
console.log(`WAVファイル保存完了: ${wavFilePath}`);
|
console.log(`WAVファイル保存完了: ${wavFilePath}`);
|
||||||
|
|
||||||
console.log(`MP3変換開始: ${wavFilePath} -> ${mp3FilePath}`);
|
console.log(`MP3変換開始: ${wavFilePath} -> ${mp3FilePath}`);
|
||||||
await new Promise<void>((resolve, reject) => {
|
Bun.spawnSync({
|
||||||
ffmpeg(wavFilePath)
|
cmd: [
|
||||||
.audioCodec("libmp3lame")
|
ffmpeg,
|
||||||
.format("mp3")
|
"-i",
|
||||||
.on("end", () => {
|
wavFilePath,
|
||||||
console.log(`MP3変換完了: ${mp3FilePath}`);
|
"-codec:a",
|
||||||
fs.unlinkSync(wavFilePath); // WAVファイルを削除
|
"libmp3lame",
|
||||||
resolve();
|
"-qscale:a",
|
||||||
})
|
"2",
|
||||||
.on("error", (err) => {
|
mp3FilePath,
|
||||||
console.error(`MP3変換エラー: ${err.message}`);
|
],
|
||||||
reject(err);
|
|
||||||
})
|
|
||||||
.save(mp3FilePath);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Wavファイルを削除
|
// Wavファイルを削除
|
||||||
|
Reference in New Issue
Block a user