logo
平台介绍
快速接入
密钥管理
文本转语音
音色克隆
音色列表
文本生成
智能体
自定义Agent
视频生成
图片生成
音乐生成
语音识别
计费规则
常见问题
工作台
立即登录

快速接入指南

本指南将协助您在 5 分钟内快速集成 SenseAudio API,开启极致的语音合成体验。

1. 获取密钥 (API Key)

  1. 登录 SenseAudio 控制台。
  2. 进入 接口密钥 页面。
  3. 点击 “新增 API Key”,复制并安全保存您的 API Key。

2. 发起请求

选择您熟悉的编程语言,复制以下代码即可直接运行:

curl

bash
复制
curl -X POST https://api.senseaudio.cn/v1/t2a_v2 \ -H "Authorization: Bearer $YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "senseaudio-tts-1.5-260319-260319", "text": "你好,这是来自 SenseAudio 的第一条语音。", "voice_setting": { "voice_id": "male_0004_a" } }'

Python

python
复制
import requests # 1. 配置 API Key 和 URL api_key = "YOUR_API_KEY" url = "https://api.senseaudio.cn/v1/t2a_v2" # 2. 准备请求数据 payload = { "model": "senseaudio-tts-1.5-260319-260319", "text": "你好,这是来自 SenseAudio 的第一条语音。", "voice_setting": { "voice_id": "male_0004_a", "speed": 1.0, "vol": 1.0, "pitch": 0 }, "audio_setting": { "format": "mp3", "sample_rate": 32000 } } headers = { "Authorization": f"Bearer {api_key}", "Content-Type": "application/json" } # 3. 发送请求 response = requests.post(url, json=payload, headers=headers) print(response.json())

JavaScript

javascript
复制
const axios = require('axios'); const apiKey = "YOUR_API_KEY"; const url = 'https://api.senseaudio.cn/v1/t2a_v2'; const payload = { model: 'senseaudio-tts-1.5-260319-260319', text: '你好,这是来自 SenseAudio 的第一条语音。', voice_setting: { voice_id: 'male_0004_a', speed: 1.0, vol: 1.0, pitch: 0 }, audio_setting: { format: 'mp3', sample_rate: 32000 } }; axios.post(url, payload, { headers: { 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' } }) .then(response => { console.log(response.data); }) .catch(error => { console.error('请求失败:', error.message); });

Go

go
复制
package main import ( "bytes" "encoding/json" "fmt" "io" "net/http" ) type TTSRequest struct { Model string `json:"model"` Text string `json:"text"` VoiceSetting VoiceSetting `json:"voice_setting"` AudioSetting AudioSetting `json:"audio_setting"` } type VoiceSetting struct { VoiceID string `json:"voice_id"` Speed float64 `json:"speed"` Vol float64 `json:"vol"` Pitch int `json:"pitch"` } type AudioSetting struct { Format string `json:"format"` SampleRate int `json:"sample_rate"` } func main() { apiKey := "YOUR_API_KEY" url := "https://api.senseaudio.cn/v1/t2a_v2" payload := TTSRequest{ Model: "senseaudio-tts-1.5-260319-260319", Text: "你好,这是来自 SenseAudio 的第一条语音。", VoiceSetting: VoiceSetting{ VoiceID: "male_0004_a", Speed: 1.0, Vol: 1.0, Pitch: 0, }, AudioSetting: AudioSetting{ Format: "mp3", SampleRate: 32000, }, } jsonData, _ := json.Marshal(payload) req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData)) req.Header.Set("Authorization", "Bearer "+apiKey) req.Header.Set("Content-Type", "application/json") client := &http.Client{} resp, err := client.Do(req) if err != nil { fmt.Println("请求失败:", err) return } defer resp.Body.Close() body, _ := io.ReadAll(resp.Body) fmt.Println(string(body)) }

Java

java
复制
import java.io.*; import java.net.HttpURLConnection; import java.net.URL; import org.json.JSONObject; public class SenseAudioQuickStart { public static void main(String[] args) { try { String apiKey = "YOUR_API_KEY"; String apiUrl = "https://api.senseaudio.cn/v1/t2a_v2"; // 构建请求体 JSONObject voiceSetting = new JSONObject(); voiceSetting.put("voice_id", "male_0004_a"); voiceSetting.put("speed", 1.0); voiceSetting.put("vol", 1.0); voiceSetting.put("pitch", 0); JSONObject audioSetting = new JSONObject(); audioSetting.put("format", "mp3"); audioSetting.put("sample_rate", 32000); JSONObject payload = new JSONObject(); payload.put("model", "senseaudio-tts-1.5-260319-260319"); payload.put("text", "你好,这是来自 SenseAudio 的第一条语音。"); payload.put("voice_setting", voiceSetting); payload.put("audio_setting", audioSetting); // 发送请求 URL url = new URL(apiUrl); HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setRequestMethod("POST"); conn.setRequestProperty("Authorization", "Bearer " + apiKey); conn.setRequestProperty("Content-Type", "application/json"); conn.setDoOutput(true); try (OutputStream os = conn.getOutputStream()) { byte[] input = payload.toString().getBytes("utf-8"); os.write(input, 0, input.length); } // 读取响应 try (BufferedReader br = new BufferedReader( new InputStreamReader(conn.getInputStream(), "utf-8"))) { StringBuilder response = new StringBuilder(); String responseLine; while ((responseLine = br.readLine()) != null) { response.append(responseLine.trim()); } System.out.println(response.toString()); } } catch (Exception e) { System.out.println("请求失败: " + e.getMessage()); } } }

下一步

  • 浏览音色库:查看 音色列表 选择适合您场景的声音。
  • 深入 API:阅读 API 文档 了解流式输出、多音色融合等高级功能。