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

快速接入指南

本指南将协助您在 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 $SENSEAUDIO_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "SenseAudio-TTS-1.0", "text": "你好,这是来自 SenseAudio 的第一条语音。", "voice_setting": { "voice_id": "child_0001_a" } }'

Python

python
复制
import requests # 1. 配置 API Key 和 URL api_key = "SENSEAUDIO_API_KEY" url = "https://api.senseaudio.cn/v1/t2a_v2" # 2. 准备请求数据 payload = { "model": "SenseAudio-TTS-1.0", "text": "你好,这是来自 SenseAudio 的第一条语音。", "voice_setting": { "voice_id": "child_0001_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 = "SENSEAUDIO_API_KEY"; const url = 'https://api.senseaudio.cn/v1/t2a_v2'; const payload = { model: 'SenseAudio-TTS-1.0', text: '你好,这是来自 SenseAudio 的第一条语音。', voice_setting: { voice_id: 'child_0001_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 := "SENSEAUDIO_API_KEY" url := "https://api.senseaudio.cn/v1/t2a_v2" payload := TTSRequest{ Model: "SenseAudio-TTS-1.0", Text: "你好,这是来自 SenseAudio 的第一条语音。", VoiceSetting: VoiceSetting{ VoiceID: "child_0001_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 = "SENSEAUDIO_API_KEY"; String apiUrl = "https://api.senseaudio.cn/v1/t2a_v2"; // 构建请求体 JSONObject voiceSetting = new JSONObject(); voiceSetting.put("voice_id", "child_0001_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.0"); 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()); } } }

Swift

swift
复制
import Foundation struct TTSRequest: Codable { let model: String let text: String let voiceSetting: VoiceSetting let audioSetting: AudioSetting enum CodingKeys: String, CodingKey { case model, text case voiceSetting = "voice_setting" case audioSetting = "audio_setting" } } struct VoiceSetting: Codable { let voiceId: String let speed: Double let vol: Double let pitch: Int enum CodingKeys: String, CodingKey { case voiceId = "voice_id" case speed, vol, pitch } } struct AudioSetting: Codable { let format: String let sampleRate: Int enum CodingKeys: String, CodingKey { case format case sampleRate = "sample_rate" } } func generateSpeech() { let apiKey = "SENSEAUDIO_API_KEY" guard let url = URL(string: "https://api.senseaudio.cn/v1/t2a_v2") else { return } let request = TTSRequest( model: "SenseAudio-TTS-1.0", text: "你好,这是来自 SenseAudio 的第一条语音。", voiceSetting: VoiceSetting(voiceId: "child_0001_a", speed: 1.0, vol: 1.0, pitch: 0), audioSetting: AudioSetting(format: "mp3", sampleRate: 32000) ) guard let jsonData = try? JSONEncoder().encode(request) else { return } var urlRequest = URLRequest(url: url) urlRequest.httpMethod = "POST" urlRequest.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization") urlRequest.setValue("application/json", forHTTPHeaderField: "Content-Type") urlRequest.httpBody = jsonData let semaphore = DispatchSemaphore(value: 0) let task = URLSession.shared.dataTask(with: urlRequest) { data, response, error in defer { semaphore.signal() } guard let data = data, error == nil else { print("请求失败: \(error?.localizedDescription ?? "Unknown error")") return } if let responseString = String(data: data, encoding: .utf8) { print(responseString) } } task.resume() semaphore.wait() } generateSpeech()

下一步

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