文字转语音 API 指南

, 11-11-2024

仅在账户充值后,API 才可使用。

JSON API 语音列表 https://speechgen.io/index.php?r=api/voices

通过 API 有两种文字配音选项:

选项 1 - 快速为短文本进行配音。
选项 2 - 设置配音任务。

集成示例

了解如何通过集成 SpeechGen.io 和自动化服务 MAKE,简化语音内容创建流程。本指南涵盖了文本转语音的自动化过程,使得生成各种应用程序的语音内容更加简单高效。

选项 1 - 快速为短文本进行配音

选项 1 的 URL: https://speechgen.io/index.php?r=api/text

将文本发送到 API,可以立即得到结果。

此选项的最大字符数为 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' - 'SekretKeyInYourProfile' 'email' - 'yourMail@gmail.com' 'voice' - 'Voice' 'text' - 'Text for text to Speech'

可选参数:

'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.

情感 不是所有语音都支持,点击此处查看

回答以 JSON 格式返回:

{ "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" - unique voice ID "status" - current voiceover status. Available from 3 values: 0 - process 1 - completed successfully -1 - error "file" - audio file path, available if status= 1 "file_cors" - audio file path CORS "error" - error text, in the event of, if status = -1 "parts" - number of voiceovers "parts_done" - number of pieces completed "duration" - audio file duration in seconds, available if status = 1 "format" - audio file format "balans" - limit balance "cost" - voiceover costs. (is increased as the voice parts are dubbed)

PHP 实现短文本配音示例 - 选项 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/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);

选项 2 - 为文本设置配音任务。

选项 2 的 URL: https://speechgen.io/index.php?r=api/longtext

步骤 1: 将文本发送到 API,并获得唯一的配音 ID (id)。
步骤 2:  发送配音 ID 请求配音结果。

此方法没有限制,最多可配音 1,000,000 字符的文本。配音任务按优先顺序进行(先到先得),可以根据文本长度,从几分钟到几分钟不等。

请求格式

$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' - 'SekretKeyInYourProfile' 'email' - 'yourMail@gmail.com' 'voice' - 'Voice' 'text' - '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.

不是所有语音都支持,点击此处查看

回答以 JSON 格式返回:

{ "id":"4153594", "status":"0", "parts":"5", "parts_done":"0", "format":"mp3", "error":"", "balans":"3331.2720000314", "cost":"0.00" }

描述:

"id" - unique voice ID "status" - current voiceover status. Available from 2 values: 1 - task added successfully -1 - error "error" - error text, in case of, if status = -1 "parts" - number of voiceovers "parts_done" - number of pieces completed "format" - audio file format "balans" - the balance of the account limits "cost" - voiceover costs. ( is increased as the voice parts are dubbed)

步骤 2:任务创建并获取到 ID 后,必须向 https://speechgen.io/index.php?r=api/result 发送请求,以查询结果。

请求格式

$data = [ 'token'=>'SekretKeyInYourProfile', 'email'=>'yourMail@gmail.com', 'id'=>4153594, ];

必填参数:

'token' - SekretKeyInYourProfile 'email' - yourMail@gmail.com 'id' - Unique voice ID obtained in step 1

回答以 JSON 格式返回:

{ "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" - unique voice ID "status" - current voiceover status. Available from 3 values: 0 - in the midst of 1 - completed successfully -1 - error "file" - audio file path, available if status = 1 "error" - error text, in case of, if status = -1 "parts" - number of voiceovers "parts_done" - number of pieces completed "duration" - audio file duration in seconds, available if status = 1 "format" - audio file format "balans" - the balance of the account limits "cost" - voiceover costs. ( is increased as the voice parts are dubbed) "cuts" - Array of fragments, if the "cut" tag is used in the text

PHP 实现短文本配音示例 - 选项 2

//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); }

我们使用Cookie来确保您在我们的网站上获得最佳体验。了解更多:隐私政策

接受Cookies