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_id、text、format を指定して 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 リファレンスで確認。
- 各サービス共通の認証ヘッダーの規約を認証で学習。