From b88aa05b8407956814487fb5975359dfcb8b742f Mon Sep 17 00:00:00 2001 From: Satsuki Akiba Date: Wed, 4 Jun 2025 12:32:11 +0900 Subject: [PATCH] feat: Remove Next.js and use environment variables --- .env.example | 1 - next.config.js | 8 -------- services/llm.ts | 4 ++-- services/tts.ts | 31 +++++++++++-------------------- 4 files changed, 13 insertions(+), 31 deletions(-) delete mode 100644 next.config.js diff --git a/.env.example b/.env.example index 145d783..11ecad7 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,5 @@ # VOICEVOXの設定 VOICEVOX_HOST=http://localhost:50021 -VOICEVOX_SPEAKER_ID=3 VOICEVOX_STYLE_ID=2 # OpenAIの設定 diff --git a/next.config.js b/next.config.js deleted file mode 100644 index d046680..0000000 --- a/next.config.js +++ /dev/null @@ -1,8 +0,0 @@ -/** @type {import('next').NextConfig} */ -const nextConfig = { - reactStrictMode: true, - output: 'standalone', - // Vite を使用している場合は Next.js の dev server は使わない -}; - -module.exports = nextConfig; diff --git a/services/llm.ts b/services/llm.ts index 6b21159..31d0cf4 100644 --- a/services/llm.ts +++ b/services/llm.ts @@ -1,8 +1,8 @@ import { OpenAI, ClientOptions } from "openai"; const clientOptions: ClientOptions = { - apiKey: import.meta.env["OPENAI_API_KEY"] ?? "", - baseURL: import.meta.env["OPENAI_API_ENDPOINT"] ?? "https://openrouter.ai/v1", + apiKey: import.meta.env["OPENAI_API_KEY"], + baseURL: import.meta.env["OPENAI_API_ENDPOINT"], }; const openai = new OpenAI(clientOptions); diff --git a/services/tts.ts b/services/tts.ts index b804808..b526179 100644 --- a/services/tts.ts +++ b/services/tts.ts @@ -2,21 +2,15 @@ import fs from "fs"; import path from "path"; // VOICEVOX APIの設定 -const VOICEVOX_HOST = - import.meta.env["VOICEVOX_HOST"] ?? "http://localhost:50021"; -const VOICEVOX_SPEAKER_ID = parseInt( - import.meta.env["VOICEVOX_SPEAKER_ID"] ?? "3", -); -const VOICEVOX_STYLE_ID = parseInt(import.meta.env["VOICEVOX_STYLE_ID"] ?? "2"); +const VOICEVOX_HOST = import.meta.env["VOICEVOX_HOST"]; +const VOICEVOX_STYLE_ID = parseInt(import.meta.env["VOICEVOX_STYLE_ID"] ?? "0"); interface VoiceStyle { - speakerId: number; styleId: number; } // 環境変数からデフォルトの声設定を取得 const defaultVoiceStyle: VoiceStyle = { - speakerId: VOICEVOX_SPEAKER_ID, styleId: VOICEVOX_STYLE_ID, }; @@ -24,16 +18,17 @@ export async function generateTTS( itemId: string, scriptText: string, ): Promise { - // 音声合成クエリの生成 - const queryResponse = await fetch(`${VOICEVOX_HOST}/audio_query`, { + const encodedText = encodeURIComponent(scriptText); + + const queryUrl = `${VOICEVOX_HOST}/audio_query?text=${encodedText}&speaker=${defaultVoiceStyle.styleId}`; + const synthesisUrl = `${VOICEVOX_HOST}/synthesis?speaker=${defaultVoiceStyle.styleId}`; + + const queryResponse = await fetch(queryUrl, { method: "POST", headers: { "Content-Type": "application/json", + Accept: "application/json", }, - body: JSON.stringify({ - text: scriptText, - speaker: defaultVoiceStyle.speakerId, - }), }); if (!queryResponse.ok) { @@ -42,16 +37,12 @@ export async function generateTTS( const audioQuery = await queryResponse.json(); - // 音声合成 - const audioResponse = await fetch(`${VOICEVOX_HOST}/synthesis`, { + const audioResponse = await fetch(synthesisUrl, { method: "POST", headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ - audio_query: audioQuery, - speaker: defaultVoiceStyle.speakerId, - }), + body: JSON.stringify(audioQuery), }); if (!audioResponse.ok) {