本指南将协助您在 5 分钟内快速集成 SenseAudio API,开启极致的语音合成体验。
选择您熟悉的编程语言,复制以下代码即可直接运行:
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"
}
}'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())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);
});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))
}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());
}
}
}