You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Postman测试Speakatoo API凭证并适配PHP应用?

Speakatoo TTS API 测试与PHP实现指南

一、Postman测试设置步骤

  1. 创建新请求
    • 选择POST请求方法,填入Speakatoo TTS API的官方合成接口地址
  2. 配置请求头
    • 添加Content-Type头,值设为application/json
  3. 填写请求体
    • 切换到Body标签,选择raw格式并设置为JSON,粘贴以下内容(替换真实用户名、密码,确认tts_resource_ids为有效音色ID):
      {
        "username": "你的真实邮箱",
        "password": "你的真实密码",
        "tts_title": "testing_API",
        "ssml_mode": 0,
        "tts_engine": "neural",
        "tts_format": "3gp",
        "tts_text": "Text for synthesize",
        "tts_resource_ids": "TRDu7S1e63c6f288f85180a9130c4e5e10f39dc7fsmJ1XYfxH",
        "synthesize_type": "save"
      }
      
    • 注意:ssml_mode是数字类型,不要加引号;确认tts_format和synthesize_type为API支持的有效值
  4. 发送请求并排查问题
    • 若返回非预期响应,优先检查:
      • 用户名/密码是否正确
      • tts_resource_ids是否与tts_engine(neural)匹配
      • 所有参数的格式、取值是否符合文档要求

二、PHP应用实现代码

使用cURL发送POST请求的示例代码:

<?php
// API端点
$apiUrl = "Speakatoo TTS API的官方合成接口地址";

// 请求参数
$postData = [
    "username" => "你的真实邮箱",
    "password" => "你的真实密码",
    "tts_title" => "testing_API",
    "ssml_mode" => 0,
    "tts_engine" => "neural",
    "tts_format" => "3gp",
    "tts_text" => "Text for synthesize",
    "tts_resource_ids" => "TRDu7S1e63c6f288f85180a9130c4e5e10f39dc7fsmJ1XYfxH",
    "synthesize_type" => "save"
];

// 初始化cURL
$ch = curl_init($apiUrl);

// 设置cURL选项
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    "Content-Type: application/json"
]);

// 执行请求并获取响应
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

// 关闭cURL
curl_close($ch);

// 处理响应
if ($httpCode === 200) {
    $result = json_decode($response, true);
    // 处理成功响应,比如获取音频链接或保存路径
    print_r($result);
} else {
    // 处理错误,输出响应内容排查问题
    echo "请求失败,状态码:" . $httpCode . "\n";
    echo "响应内容:" . $response;
}
?>

实现注意事项

  • 确保服务器已开启cURL扩展
  • 敏感信息(用户名、密码)建议通过环境变量存储,不要硬编码
  • 增加JSON解码错误捕获逻辑,避免因响应格式异常导致程序崩溃

内容的提问来源于stack exchange,提问作者Nishu Nath

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.14 17:05:25