feat: Remove Next.js and use environment variables
This commit is contained in:
		@@ -1,6 +1,5 @@
 | 
				
			|||||||
# VOICEVOXの設定
 | 
					# VOICEVOXの設定
 | 
				
			||||||
VOICEVOX_HOST=http://localhost:50021
 | 
					VOICEVOX_HOST=http://localhost:50021
 | 
				
			||||||
VOICEVOX_SPEAKER_ID=3
 | 
					 | 
				
			||||||
VOICEVOX_STYLE_ID=2
 | 
					VOICEVOX_STYLE_ID=2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
# OpenAIの設定
 | 
					# OpenAIの設定
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,8 +0,0 @@
 | 
				
			|||||||
/** @type {import('next').NextConfig} */
 | 
					 | 
				
			||||||
const nextConfig = {
 | 
					 | 
				
			||||||
  reactStrictMode: true,
 | 
					 | 
				
			||||||
  output: 'standalone',
 | 
					 | 
				
			||||||
  // Vite を使用している場合は Next.js の dev server は使わない
 | 
					 | 
				
			||||||
};
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
module.exports = nextConfig;
 | 
					 | 
				
			||||||
@@ -1,8 +1,8 @@
 | 
				
			|||||||
import { OpenAI, ClientOptions } from "openai";
 | 
					import { OpenAI, ClientOptions } from "openai";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const clientOptions: ClientOptions = {
 | 
					const clientOptions: ClientOptions = {
 | 
				
			||||||
  apiKey: import.meta.env["OPENAI_API_KEY"] ?? "",
 | 
					  apiKey: import.meta.env["OPENAI_API_KEY"],
 | 
				
			||||||
  baseURL: import.meta.env["OPENAI_API_ENDPOINT"] ?? "https://openrouter.ai/v1",
 | 
					  baseURL: import.meta.env["OPENAI_API_ENDPOINT"],
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
const openai = new OpenAI(clientOptions);
 | 
					const openai = new OpenAI(clientOptions);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -2,21 +2,15 @@ import fs from "fs";
 | 
				
			|||||||
import path from "path";
 | 
					import path from "path";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// VOICEVOX APIの設定
 | 
					// VOICEVOX APIの設定
 | 
				
			||||||
const VOICEVOX_HOST =
 | 
					const VOICEVOX_HOST = import.meta.env["VOICEVOX_HOST"];
 | 
				
			||||||
  import.meta.env["VOICEVOX_HOST"] ?? "http://localhost:50021";
 | 
					const VOICEVOX_STYLE_ID = parseInt(import.meta.env["VOICEVOX_STYLE_ID"] ?? "0");
 | 
				
			||||||
const VOICEVOX_SPEAKER_ID = parseInt(
 | 
					 | 
				
			||||||
  import.meta.env["VOICEVOX_SPEAKER_ID"] ?? "3",
 | 
					 | 
				
			||||||
);
 | 
					 | 
				
			||||||
const VOICEVOX_STYLE_ID = parseInt(import.meta.env["VOICEVOX_STYLE_ID"] ?? "2");
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
interface VoiceStyle {
 | 
					interface VoiceStyle {
 | 
				
			||||||
  speakerId: number;
 | 
					 | 
				
			||||||
  styleId: number;
 | 
					  styleId: number;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 環境変数からデフォルトの声設定を取得
 | 
					// 環境変数からデフォルトの声設定を取得
 | 
				
			||||||
const defaultVoiceStyle: VoiceStyle = {
 | 
					const defaultVoiceStyle: VoiceStyle = {
 | 
				
			||||||
  speakerId: VOICEVOX_SPEAKER_ID,
 | 
					 | 
				
			||||||
  styleId: VOICEVOX_STYLE_ID,
 | 
					  styleId: VOICEVOX_STYLE_ID,
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -24,16 +18,17 @@ export async function generateTTS(
 | 
				
			|||||||
  itemId: string,
 | 
					  itemId: string,
 | 
				
			||||||
  scriptText: string,
 | 
					  scriptText: string,
 | 
				
			||||||
): Promise<string> {
 | 
					): Promise<string> {
 | 
				
			||||||
  // 音声合成クエリの生成
 | 
					  const encodedText = encodeURIComponent(scriptText);
 | 
				
			||||||
  const queryResponse = await fetch(`${VOICEVOX_HOST}/audio_query`, {
 | 
					
 | 
				
			||||||
 | 
					  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",
 | 
					    method: "POST",
 | 
				
			||||||
    headers: {
 | 
					    headers: {
 | 
				
			||||||
      "Content-Type": "application/json",
 | 
					      "Content-Type": "application/json",
 | 
				
			||||||
 | 
					      Accept: "application/json",
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    body: JSON.stringify({
 | 
					 | 
				
			||||||
      text: scriptText,
 | 
					 | 
				
			||||||
      speaker: defaultVoiceStyle.speakerId,
 | 
					 | 
				
			||||||
    }),
 | 
					 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!queryResponse.ok) {
 | 
					  if (!queryResponse.ok) {
 | 
				
			||||||
@@ -42,16 +37,12 @@ export async function generateTTS(
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
  const audioQuery = await queryResponse.json();
 | 
					  const audioQuery = await queryResponse.json();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // 音声合成
 | 
					  const audioResponse = await fetch(synthesisUrl, {
 | 
				
			||||||
  const audioResponse = await fetch(`${VOICEVOX_HOST}/synthesis`, {
 | 
					 | 
				
			||||||
    method: "POST",
 | 
					    method: "POST",
 | 
				
			||||||
    headers: {
 | 
					    headers: {
 | 
				
			||||||
      "Content-Type": "application/json",
 | 
					      "Content-Type": "application/json",
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    body: JSON.stringify({
 | 
					    body: JSON.stringify(audioQuery),
 | 
				
			||||||
      audio_query: audioQuery,
 | 
					 | 
				
			||||||
      speaker: defaultVoiceStyle.speakerId,
 | 
					 | 
				
			||||||
    }),
 | 
					 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (!audioResponse.ok) {
 | 
					  if (!audioResponse.ok) {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user