Skip to content

Instantly share code, notes, and snippets.

@mongonta0716
Created July 23, 2025 08:40
Show Gist options
  • Save mongonta0716/7c453eb204287eead7f00f37f28232cc to your computer and use it in GitHub Desktop.
Save mongonta0716/7c453eb204287eead7f00f37f28232cc to your computer and use it in GitHub Desktop.
Aivis Cloud APIをModuleLLM上で実行する。
import requests
import pyaudio
import wave
import io
API_KEY = 'YOUR_API_KEY' # ←ご自身のAPIキー
ENDPOINT = 'https://api.aivis-project.com/v1/tts/synthesize'
MODEL_UUID = '使いたいUUID' # ←/v1/list-voicesで取得
payload = {
"text": "こんにちは。WAV形式のストリーミング再生テストです。ModuleLLM上のLinuxで再生しています。",
"voice": "aivis_moe", # 適切なvoice名
"model_uuid": MODEL_UUID,
"speed": 1.0,
"volume_gain": 0.0,
"emotion": "neutral",
"output_sampling_rate": 16000, # ModuleLLMのスピーカーは16,000Hzのみ対応
"output_format": "wav" # ←必ず指定
}
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
# ストリーミングモードでリクエスト送信
response = requests.post(ENDPOINT, headers=headers, json=payload, stream=True)
if response.status_code == 200:
# バイナリ受信 → メモリバッファに格納
audio_buffer = io.BytesIO()
for chunk in response.iter_content(chunk_size=4096):
if chunk:
audio_buffer.write(chunk)
audio_buffer.seek(0)
# waveでデコード
with wave.open(audio_buffer, 'rb') as wf:
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
channels=wf.getnchannels(),
rate=wf.getframerate(),
output=True,
output_device_index=1) # indexは別途, pyaudio_index_list.pyで調べる必要あり。
data = wf.readframes(1024)
while len(data) > 0:
stream.write(data)
data = wf.readframes(1024)
stream.stop_stream()
stream.close()
p.terminate()
else:
print("エラー:", response.status_code, response.text)
import pyaudio
p = pyaudio.PyAudio()
for i in range(p.get_device_count()):
info = p.get_device_info_by_index(i)
print(f"{i}: {info['name']}")
p.terminate()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment