API instruction for Text to Speech

, 27-12-2024

API hanya tersedia selepas anda membiayai akaun anda.

Suara API JSON https://speechgen.io/index.php?r=api/voices.

Terdapat 2 pilihan untuk membuat alih suara teks melalui API:

Pilihan 1 - alih suara cepat untuk teks pendek.
Pilihan 2 - menetapkan tugasan alih suara.

Contoh Integrasi

Ketahui cara untuk mempermudah penciptaan kandungan suara dengan mengintegrasikan SpeechGen.io dengan perkhidmatan automasi MAKE. Panduan ini merangkumi automasi proses teks-ke-ucapan, menjadikannya lebih mudah dan efisien untuk menghasilkan kandungan suara untuk pelbagai aplikasi.

Pilihan 1 - alih suara cepat untuk teks pendek

URL untuk varian 1: https://speechgen.io/index.php?r=api/text

Teks dihantar ke API, anda mendapat hasil serta-merta.

Pilihan ini mempunyai had maksimum sebanyak 2000 aksara. Dan juga maksimum 2 perubahan suara. Jika had melebihi, anda akan menerima ralat (status = -1).

Format Permintaan

$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, ];

Parameter Wajib:

'token' - 'SekretKeyInYourProfile' 'email' - 'yourMail@gmail.com' 'voice' - 'Voice' 'text' - 'Text for text to Speech'

Parameter Pilihan:

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

Emosi Tidak tersedia untuk semua suara, lihat di sini.

Jawapan datang dalam format 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" }

Penerangan:

"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)

Contoh alih suara teks pendek dalam PHP varian 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);

Pilihan 2 adalah menetapkan tugasan alih suara untuk teks.

URL untuk pilihan 2: https://speechgen.io/index.php?r=api/longtext

Langkah 1: Teks dihantar ke API dan ID suara unik diperoleh (id).
Langkah 2:  Permintaan hasil proses alih suara dihantar dengan menggunakan ID alih suara (id).

Kaedah ini tidak mempunyai had dan membolehkan alih suara teks sehingga 1,000,000 aksara. Proses alih suara dijalankan secara keutamaan (siapa cepat dia dapat) dan boleh mengambil masa dari 1 hingga beberapa minit, bergantung pada panjang teks.

Format Permintaan

$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, ];

Parameter Wajib:

'token' - 'SekretKeyInYourProfile' 'email' - 'yourMail@gmail.com' 'voice' - 'Voice' 'text' - 'Text'

Parameter Pilihan:

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

Tidak tersedia untuk semua suara, lihat di sini.

Jawapan datang dalam format JSON:

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

Penerangan:

"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)

Langkah 2. Selepas membuat tugasan dan memperoleh ID (id), permintaan mesti dihantar ke https://speechgen.io/index.php?r=api/result, untuk mengetahui hasil.

Format Permintaan

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

Parameter Wajib:

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

Jawapan datang dalam format 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" }

Penerangan:

"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

Contoh alih suara teks ujian pendek dalam PHP varian 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); }

Kami menggunakan kuki untuk memastikan anda mendapat pengalaman terbaik di laman web kami. Ketahui lebih lanjut: Dasar Privasi

Terima Kuki