mirror of
https://github.com/taigrr/elevenlabs.git
synced 2026-04-02 03:08:57 -07:00
start tts rewrite
This commit is contained in:
@@ -1,209 +0,0 @@
|
||||
|
||||
/*
|
||||
* ElevenLabs API Documentation
|
||||
*
|
||||
* This is the documentation for the ElevenLabs API. You can use this API to use our service programmatically, this is done by using your xi-api-key. <br/> You can view your xi-api-key using the 'Profile' tab on https://beta.elevenlabs.io. Our API is experimental so all endpoints are subject to change.
|
||||
*
|
||||
* API version: 1.0
|
||||
* Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git)
|
||||
*/
|
||||
package swagger
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"fmt"
|
||||
"github.com/antihax/optional"
|
||||
)
|
||||
|
||||
// Linger please
|
||||
var (
|
||||
_ context.Context
|
||||
)
|
||||
|
||||
type TextToSpeechApiService service
|
||||
/*
|
||||
TextToSpeechApiService Text To Speech
|
||||
Converts text into speech using a voice of your choice and returns audio.
|
||||
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
||||
* @param body
|
||||
* @param voiceId Voice ID to be used, you can use https://api.elevenlabs.io/v1/voices to list all the available voices.
|
||||
* @param optional nil or *TextToSpeechApiTextToSpeechV1TextToSpeechVoiceIdPostOpts - Optional Parameters:
|
||||
* @param "XiApiKey" (optional.String) - Your API key. This is required by most endpoints to access our API programatically. You can view your xi-api-key using the 'Profile' tab on the website.
|
||||
|
||||
*/
|
||||
|
||||
type TextToSpeechApiTextToSpeechV1TextToSpeechVoiceIdPostOpts struct {
|
||||
XiApiKey optional.String
|
||||
}
|
||||
|
||||
func (a *TextToSpeechApiService) TextToSpeechV1TextToSpeechVoiceIdPost(ctx context.Context, body BodyTextToSpeechV1TextToSpeechVoiceIdPost, voiceId string, localVarOptionals *TextToSpeechApiTextToSpeechV1TextToSpeechVoiceIdPostOpts) (*http.Response, error) {
|
||||
var (
|
||||
localVarHttpMethod = strings.ToUpper("Post")
|
||||
localVarPostBody interface{}
|
||||
localVarFileName string
|
||||
localVarFileBytes []byte
|
||||
|
||||
)
|
||||
|
||||
// create path and map variables
|
||||
localVarPath := a.client.cfg.BasePath + "/v1/text-to-speech/{voice_id}"
|
||||
localVarPath = strings.Replace(localVarPath, "{"+"voice_id"+"}", fmt.Sprintf("%v", voiceId), -1)
|
||||
|
||||
localVarHeaderParams := make(map[string]string)
|
||||
localVarQueryParams := url.Values{}
|
||||
localVarFormParams := url.Values{}
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string{"application/json"}
|
||||
|
||||
// set Content-Type header
|
||||
localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
localVarHeaderParams["Content-Type"] = localVarHttpContentType
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string{"audio/mpeg", "application/json"}
|
||||
|
||||
// set Accept header
|
||||
localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
|
||||
}
|
||||
if localVarOptionals != nil && localVarOptionals.XiApiKey.IsSet() {
|
||||
localVarHeaderParams["xi-api-key"] = parameterToString(localVarOptionals.XiApiKey.Value(), "")
|
||||
}
|
||||
// body params
|
||||
localVarPostBody = &body
|
||||
r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
localVarHttpResponse, err := a.client.callAPI(r)
|
||||
if err != nil || localVarHttpResponse == nil {
|
||||
return localVarHttpResponse, err
|
||||
}
|
||||
|
||||
localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
|
||||
localVarHttpResponse.Body.Close()
|
||||
if err != nil {
|
||||
return localVarHttpResponse, err
|
||||
}
|
||||
|
||||
|
||||
if localVarHttpResponse.StatusCode >= 300 {
|
||||
newErr := GenericSwaggerError{
|
||||
body: localVarBody,
|
||||
error: localVarHttpResponse.Status,
|
||||
}
|
||||
if localVarHttpResponse.StatusCode == 422 {
|
||||
var v HttpValidationError
|
||||
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
|
||||
if err != nil {
|
||||
newErr.error = err.Error()
|
||||
return localVarHttpResponse, newErr
|
||||
}
|
||||
newErr.model = v
|
||||
return localVarHttpResponse, newErr
|
||||
}
|
||||
return localVarHttpResponse, newErr
|
||||
}
|
||||
|
||||
return localVarHttpResponse, nil
|
||||
}
|
||||
/*
|
||||
TextToSpeechApiService Text To Speech
|
||||
Converts text into speech using a voice of your choice and returns audio as an audio stream.
|
||||
* @param ctx context.Context - for authentication, logging, cancellation, deadlines, tracing, etc. Passed from http.Request or context.Background().
|
||||
* @param body
|
||||
* @param voiceId Voice ID to be used, you can use https://api.elevenlabs.io/v1/voices to list all the available voices.
|
||||
* @param optional nil or *TextToSpeechApiTextToSpeechV1TextToSpeechVoiceIdStreamPostOpts - Optional Parameters:
|
||||
* @param "XiApiKey" (optional.String) - Your API key. This is required by most endpoints to access our API programatically. You can view your xi-api-key using the 'Profile' tab on the website.
|
||||
|
||||
*/
|
||||
|
||||
type TextToSpeechApiTextToSpeechV1TextToSpeechVoiceIdStreamPostOpts struct {
|
||||
XiApiKey optional.String
|
||||
}
|
||||
|
||||
func (a *TextToSpeechApiService) TextToSpeechV1TextToSpeechVoiceIdStreamPost(ctx context.Context, body BodyTextToSpeechV1TextToSpeechVoiceIdStreamPost, voiceId string, localVarOptionals *TextToSpeechApiTextToSpeechV1TextToSpeechVoiceIdStreamPostOpts) (*http.Response, error) {
|
||||
var (
|
||||
localVarHttpMethod = strings.ToUpper("Post")
|
||||
localVarPostBody interface{}
|
||||
localVarFileName string
|
||||
localVarFileBytes []byte
|
||||
|
||||
)
|
||||
|
||||
// create path and map variables
|
||||
localVarPath := a.client.cfg.BasePath + "/v1/text-to-speech/{voice_id}/stream"
|
||||
localVarPath = strings.Replace(localVarPath, "{"+"voice_id"+"}", fmt.Sprintf("%v", voiceId), -1)
|
||||
|
||||
localVarHeaderParams := make(map[string]string)
|
||||
localVarQueryParams := url.Values{}
|
||||
localVarFormParams := url.Values{}
|
||||
|
||||
// to determine the Content-Type header
|
||||
localVarHttpContentTypes := []string{"application/json"}
|
||||
|
||||
// set Content-Type header
|
||||
localVarHttpContentType := selectHeaderContentType(localVarHttpContentTypes)
|
||||
if localVarHttpContentType != "" {
|
||||
localVarHeaderParams["Content-Type"] = localVarHttpContentType
|
||||
}
|
||||
|
||||
// to determine the Accept header
|
||||
localVarHttpHeaderAccepts := []string{"application/json"}
|
||||
|
||||
// set Accept header
|
||||
localVarHttpHeaderAccept := selectHeaderAccept(localVarHttpHeaderAccepts)
|
||||
if localVarHttpHeaderAccept != "" {
|
||||
localVarHeaderParams["Accept"] = localVarHttpHeaderAccept
|
||||
}
|
||||
if localVarOptionals != nil && localVarOptionals.XiApiKey.IsSet() {
|
||||
localVarHeaderParams["xi-api-key"] = parameterToString(localVarOptionals.XiApiKey.Value(), "")
|
||||
}
|
||||
// body params
|
||||
localVarPostBody = &body
|
||||
r, err := a.client.prepareRequest(ctx, localVarPath, localVarHttpMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams, localVarFileName, localVarFileBytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
localVarHttpResponse, err := a.client.callAPI(r)
|
||||
if err != nil || localVarHttpResponse == nil {
|
||||
return localVarHttpResponse, err
|
||||
}
|
||||
|
||||
localVarBody, err := ioutil.ReadAll(localVarHttpResponse.Body)
|
||||
localVarHttpResponse.Body.Close()
|
||||
if err != nil {
|
||||
return localVarHttpResponse, err
|
||||
}
|
||||
|
||||
|
||||
if localVarHttpResponse.StatusCode >= 300 {
|
||||
newErr := GenericSwaggerError{
|
||||
body: localVarBody,
|
||||
error: localVarHttpResponse.Status,
|
||||
}
|
||||
if localVarHttpResponse.StatusCode == 422 {
|
||||
var v HttpValidationError
|
||||
err = a.client.decode(&v, localVarBody, localVarHttpResponse.Header.Get("Content-Type"));
|
||||
if err != nil {
|
||||
newErr.error = err.Error()
|
||||
return localVarHttpResponse, newErr
|
||||
}
|
||||
newErr.model = v
|
||||
return localVarHttpResponse, newErr
|
||||
}
|
||||
return localVarHttpResponse, newErr
|
||||
}
|
||||
|
||||
return localVarHttpResponse, nil
|
||||
}
|
||||
25
client/tts.go
Normal file
25
client/tts.go
Normal file
@@ -0,0 +1,25 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/taigrr/elevenlabs/client/types"
|
||||
)
|
||||
|
||||
func (c Client) TextToSpeechV1TextToSpeechVoiceIdPostWriter(ctx context.Context, w io.Writer, voiceID string, options types.SynthesisOptions) ([]byte, error) {
|
||||
localVarHttpMethod = strings.ToUpper("Post")
|
||||
localVarPath := a.client.cfg.BasePath + "/v1/text-to-speech/{voice_id}"
|
||||
}
|
||||
|
||||
func (c Client) TextToSpeechV1TextToSpeechVoiceIdPost(ctx context.Context, voiceID string, options types.SynthesisOptions) ([]byte, error) {
|
||||
localVarHttpMethod = strings.ToUpper("Post")
|
||||
localVarPath := a.client.cfg.BasePath + "/v1/text-to-speech/{voice_id}"
|
||||
}
|
||||
|
||||
func (c Client) TextToSpeechV1TextToSpeechVoiceIdStreamPost(ctx context.Context, w io.Writer, voiceId string, options types.SynthesisOptions) error {
|
||||
localVarHttpMethod = strings.ToUpper("Post")
|
||||
|
||||
localVarPath := a.client.cfg.BasePath + "/v1/text-to-speech/{voice_id}/stream"
|
||||
}
|
||||
Reference in New Issue
Block a user