メインコンテンツまでスキップ

TTS クイックスタート

この​ガイドでは、​Shisa TTS で​最初の​音声を​生成します。​API キーが​必要です。Shisa プラットフォームで​作成してください。​新規アカウントには​ $10 分の​無料クレジット が​含まれます。

1. エンドポイントと​キーを​設定する

すべての​リクエストを​標準の​ベアラートークンで​認証します。

Endpoint: https://api.shisa.ai/tts
Auth: Authorization: Bearer YOUR_API_KEY
ヒント

API キーを​ソース管理に​含めないでください。​実際の​アプリケーションでは、​環境変数​(例: SHISA_API_KEY)から​読み込んでください。

2. 音声を​生成する

希望する​ voice_idtextformat を​指定して​ POST リクエストを​送信します。​以下の​例では​音声 c3abe79a-99b3-4a5f-8549-f5cb42985291 を​使用しています。

curl
# List available voices
curl -s -X GET "https://api.shisa.ai/tts/voices" \
-H "Authorization: Bearer YOUR_API_KEY" | jq .

# Generate speech
curl -s -X POST "https://api.shisa.ai/tts" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"voice_id": "c3abe79a-99b3-4a5f-8549-f5cb42985291",
"format": "mp3",
"stream": false,
"text": "こんにちは。Shisa APIへようこそ。"
}' \
--output speech.mp3

# Stream audio directly to a player
curl -s -X POST "https://api.shisa.ai/tts" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"voice_id": "c3abe79a-99b3-4a5f-8549-f5cb42985291",
"format": "mp3",
"stream": true,
"text": "ストリーミングテストです。"
}' \
--output - | ffplay -nodisp -autoexit -
Python
import requests

API_URL = "https://api.shisa.ai"
API_KEY = "YOUR_API_KEY"
HEADERS = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}

# List available voices
def list_voices():
response = requests.get(f"{API_URL}/tts/voices", headers=HEADERS)
return response.json()

# Generate speech
def generate_speech(text, voice_id="c3abe79a-99b3-4a5f-8549-f5cb42985291", format="mp3", stream=False):
response = requests.post(
f"{API_URL}/tts",
headers=HEADERS,
json={
"voice_id": voice_id,
"format": format,
"stream": stream,
"text": text
},
stream=stream
)

output_file = f"output.{format}"
with open(output_file, "wb") as f:
if stream:
for chunk in response.iter_content():
f.write(chunk)
else:
f.write(response.content)

return output_file

# Example usage
voices = list_voices()
print(voices)

audio_file = generate_speech(
"お客様の声を大切にしています。",
voice_id="c3abe79a-99b3-4a5f-8549-f5cb42985291"
)
JavaScript
const API_URL = 'https://api.shisa.ai';
const API_KEY = 'YOUR_API_KEY';
const headers = {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
};

// List available voices
const listVoices = async () => {
const response = await fetch(`${API_URL}/tts/voices`, { headers });
return response.json();
};

// Generate speech
const generateSpeech = async (text, voiceId = 'c3abe79a-99b3-4a5f-8549-f5cb42985291', format = 'mp3') => {
const response = await fetch(`${API_URL}/tts`, {
method: 'POST',
headers,
body: JSON.stringify({
voice_id: voiceId,
format,
stream: true,
text,
}),
});

// Handle streaming response
const reader = response.body.getReader();
const chunks = [];

while (true) {
const { done, value } = await reader.read();
if (done) break;
chunks.push(value);
}

// Combine chunks and create audio blob
const blob = new Blob(chunks, { type: `audio/${format}` });
const url = URL.createObjectURL(blob);

// Play audio
const audio = new Audio(url);
audio.play();
};

// Example usage
const voices = await listVoices();
console.log(voices);

await generateSpeech('ようこそ、Shisa APIへ。', 'c3abe79a-99b3-4a5f-8549-f5cb42985291');

3. 音声を​再生する

レスポンスは​ JSON ではなく​ バイナリ音声 です。​リクエストは​それを​直接ファイル​(speech.mp3)に​書き込みます。​任意の​音声ツールで​再生してください。

# Play the generated audio
ffplay -nodisp -autoexit speech.mp3

# Or stream directly
curl -s -X POST "https://api.shisa.ai/tts" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"voice_id": "c3abe79a-99b3-4a5f-8549-f5cb42985291", "format": "mp3", "stream": true, "text": "ストリーミングテストです。"}' \
--output - | ffplay -nodisp -autoexit -
注記

ストリーミング​("stream": true)は​ streaming: true の​音声で​のみ​利用できます。​音声の​対応状況は音声カタログで​確認してください。

次の​ステップ

  • 音声で​利用​可能な​すべての​音声を​閲覧。
  • すべての​パラメータ、​レスポンス形式、​エラーコードを​ API リファレンスで​確認。
  • 各サービス共通の​認証ヘッダーの​規約を認証で​学習。