08-09-2025 , 08-09-2025
只有在账户充值后才能使用 API。
JSON API 声音 https://speechgen.io/index.php?r=api/voices。
API 提供 2 种文本配音选项:
选项 1 - 快速配音短文本。
选项 2 - 设置配音任务。
了解如何通过集成 SpeechGen.io 与自动化服务 MAKE 来简化语音内容创作。本指南涵盖了文本到语音流程的自动化,使为各种应用生成语音内容更加简单高效。
选项 1 的网址:https://speechgen.io/index.php?r=api/text
此选项的最大字符限制为 2000 个。最多只能更改 2 次声音。如果超出限制,您将收到错误(状态 = -1)。
$data = [
'token'=>'SekretKeyInYourProfile',
'email'=>'yourMail@gmail.com',
'voice'=>'John',
'text'=>"Text for text to Speech",
'format'=>'mp3',
'speed'=>1.1,
'pitch'=>0.8,
'emotion'=>'good',
'pause_sentence'=>300,
'pause_paragraph'=>400,
'bitrate'=>48000,
];
'token' - '您个人资料中的密钥'
'email' - '您的邮箱@gmail.com'
'voice' - '声音'
'text' - '用于文本转语音的文本'
'format' - format of the resulting file, by default = mp3, possible values ( 'mp3', 'wav', 'ogg')
'speed' - playback speed, by default 1, (range from 0.1 to 2.0)
'pitch'- voice pitch, by default 0, (range from -20 to 20)
'emotion' - emotion of voice , by default 'good', possible values ( 'good', 'evil', 'neutral').
'pause_sentence' - The size of the pause between sentences in milliseconds.
'pause_paragraph' - The size of the pause between paragraphs in milliseconds.
'bitrate'=>48000 - Bitrate from 8000 to 192000 Hz.
情绪并非适用于所有声音,请在此查看。
{
"id":"4153594",
"status":"0",
"file":"result.mp3",
"file_cors":"result_cors.mp3",
"parts":"5",
"parts_done":"2",
"duration":"0",
"format":"mp3",
"error":"",
"balans":"3331.2720000314",
"cost":"0.06"
}
"id" - 唯一的声音 ID
"status" - 当前配音状态。有 3 种可用值:
0 - 处理中
1 - 成功完成
-1 - 错误
"file" - 音频文件路径,当 status= 1 时可用
"file_cors" - 音频文件路径 CORS
"error" - 错误文本,在 status = -1 时显示
"parts" - 配音片段数量
"parts_done" - 已完成的片段数量
"duration" - 音频文件时长(秒),当 status = 1 时可用
"format" - 音频文件格式
"balans" - 账户限额余额
"cost" - 配音费用。(配音片段越多,费用越高)
$data = [
'token' => '123456',
'email' => 'mail@mail.com',
'voice' => 'John',
'text' => "Text",
'format' => 'mp3',
'speed' => 1.1,
'pitch' => 0,
'emotion' => 'good',
];
$url = "https://speechgen.io/index.php?r=api/text";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$response = curl_exec($ch);
var_dump($response);
$response = json_decode($response, true);
if (curl_errno($ch)) {
var_dump("Connection error with text recognition server, " . curl_error($ch));
} else {
var_dump($response);
if ($response["status"] == 1) {
//Copy
echo " ok " . $response["file"];
copy($response["file"], 'Filename.' . $response["format"]);
} else {
//Error, no voiceover possible
echo $response["error"];
}
}
curl_close($ch);
步骤 1:将文本发送到 API 并获取唯一的声音 ID (id)。
步骤 2: 通过发送配音标识符 (id) 来请求配音结果。
此方法没有限制,允许配音长达 1,000,000 个字符的文本。配音按优先级顺序进行(先到先得),根据文本长度可能需要 1 到几分钟。
$data = [
'token'=>'SekretKeyInYourProfile',
'email'=>'yourMail@gmail.com',
'voice'=>'John',
'text'=>"Text",
'format'=>'mp3',
'speed'=>1.1,
'pitch'=>0.8,
'emotion'=>'good',
'pause_sentence'=>300,
'pause_paragraph'=>400,
'bitrate'=>48000,
];
'token' - '您个人资料中的密钥'
'email' - '您的邮箱@gmail.com'
'voice' - '声音'
'text' - '文本'
'format' - format of the resulting file, by default = mp3, possible values( 'mp3', 'wav', 'ogg')
'speed' - speed, by default 1, (range from 0.1 to 2.0)
'pitch'- voice pitch, by default 0, (range from -20 to 20)
'emotion' - emotional coloration, by default 'good', possible values ( 'good', 'evil', 'neutral').
'pause_sentence' - The size of the pause between sentences in milliseconds.
'pause_paragraph' - The size of the pause between paragraphs in milliseconds.
'bitrate'=>48000 - Bitrate from 8000 to 192000 Hz.
并非适用于所有声音,请在此查看。
{
"id":"4153594",
"status":"0",
"parts":"5",
"parts_done":"0",
"format":"mp3",
"error":"",
"balans":"3331.2720000314",
"cost":"0.00"
}
"id" - 唯一的声音 ID
"status" - 当前配音状态。有 2 种可用值:
1 - 任务已成功添加
-1 - 错误
"error" - 错误文本,在 status = -1 时显示
"parts" - 配音片段数量
"parts_done" - 已完成的片段数量
"format" - 音频文件格式
"balans" - 账户限额余额
"cost" - 配音费用。(配音片段越多,费用越高)
步骤 2。创建任务并获取标识符 (id) 后,必须发送请求到 https://speechgen.io/index.php?r=api/result,以查询结果。
$data = [
'token'=>'SekretKeyInYourProfile',
'email'=>'yourMail@gmail.com',
'id'=>4153594,
];
'token' - 您个人资料中的密钥
'email' - 您的邮箱@gmail.com
'id' - 步骤 1 中获取的唯一声音 ID
{
"id":"4153594",
"status":"0",
"file":"result.mp3",
"cuts":["result_1.mp3","result_2.mp3",...],
"parts":"5",
"parts_done":"0",
"format":"mp3",
"error":"",
"balans":"3331.2720000314",
"cost":"0.00"
}
"id" - 唯一的声音 ID
"status" - 当前配音状态。有 3 种可用值:
0 - 进行中
1 - 成功完成
-1 - 错误
"file" - 音频文件路径,当 status = 1 时可用
"error" - 错误文本,在 status = -1 时显示
"parts" - 配音片段数量
"parts_done" - 已完成的片段数量
"duration" - 音频文件时长(秒),当 status = 1 时可用
"format" - 音频文件格式
"balans" - 账户限额余额
"cost" - 配音费用。(配音片段越多,费用越高)
"cuts" - 片段数组,如果文本中使用了“cut”标签
//STEP 1
$data = [
'token' => '123456',
'email' => 'mail@mail.com',
'voice' => 'John',
'text' => "Text",
'format' => 'mp3',
'speed' => 1.1,
'pitch' => 0,
'emotion' => 'good',
];
$url = "https://speechgen.io/index.php?r=api/longtext";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$response = curl_exec($ch);
var_dump($response);
$response = json_decode($response, true);
$resultId = 0;
if (curl_errno($ch)) {
var_dump("Error in connecting to the text recognition server, " . curl_error($ch));
} else {
var_dump($response);
if ($response["status"] == 1) {
//Copy
echo " ok " . $response["file"];
copy($response["file"], 'FileName.' . $response["format"]);
} elseif ($response["status"] == 0) {
//Remember the voice ID, and ask for the result later
$resultId = $response["id"];
} else {
//Error, no voiceover possible
echo $response["error"];
}
}
curl_close($ch);
//STEP 2
// Every minute we make a query-check of the result
if($resultId){
$data = [
'token'=>'123456',
'email'=>'mail@mail.com',
'id'=>$resultId,
];
$url = "https://speechgen.io/index.php?r=api/result";
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
$response = curl_exec($ch);
var_dump($response);
$response = json_decode($response,true);
if (curl_errno($ch)) {
var_dump("Error in connecting to the text recognition server, ".curl_error($ch));
}else{
var_dump($response);
if($response["status"] == 1){
//Copy
echo " ok ".$response["file"];
copy($response["file"], 'FileMane.' . $response["format"]);
}elseif($response["status"] == 0){
//Not ready yet, we will ask for the result later
echo "In process...";
}else{
//Error, no voiceover possible
echo $response["error"];
}
}
curl_close($ch);
}