From eb96ca97341364ee8c761d1c2476f1c493abc458 Mon Sep 17 00:00:00 2001 From: Allan Nava Date: Tue, 2 May 2023 08:11:57 +0200 Subject: [PATCH] added generate tts audio --- fakeyou/fakeyou.go | 1 + fakeyou/request.go | 6 ++++++ fakeyou/response.go | 5 +++++ fakeyou/voice_api.go | 34 ++++++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+) diff --git a/fakeyou/fakeyou.go b/fakeyou/fakeyou.go index 3ee817b..b5aaae1 100644 --- a/fakeyou/fakeyou.go +++ b/fakeyou/fakeyou.go @@ -11,6 +11,7 @@ type IFakeYou interface { // voice api GetListOfVoices() (*ResponseVoice, error) GetListOfVoiceCategories() (*ResponseVoiceCategories, error) + GenerateTTSAudio(text string, ttsModelToken string) (*ResponseGenerateTTS, error) // auth api Login(body RequestLogin) error } diff --git a/fakeyou/request.go b/fakeyou/request.go index e65384f..0f66ea6 100644 --- a/fakeyou/request.go +++ b/fakeyou/request.go @@ -4,3 +4,9 @@ type RequestLogin struct { Username string `json:"username_or_email" required:"true" validate:"nonnil,min=1"` Password string `json:"password" required:"true" validate:"nonnil,min=4"` } + +type RequestGenerateTTS struct { + TTSModelToken string `json:"tts_model_token" required:"true" validate:"nonnil,min=4"` + UUIDIdempotencyToken string `json:"uuid_idempotency_token" required:"true" validate:"nonnil,min=4"` + InferenceText string `json:"inference_text" required:"true" validate:"nonnil,min=4"` +} diff --git a/fakeyou/response.go b/fakeyou/response.go index 5bac668..6514980 100644 --- a/fakeyou/response.go +++ b/fakeyou/response.go @@ -84,3 +84,8 @@ type ResponseVoiceCategories struct { BaseResponse Categories []Category `json:"categories"` } + +type ResponseGenerateTTS struct { + BaseResponse + InferenceJobToken string `json:"inference_job_token"` +} diff --git a/fakeyou/voice_api.go b/fakeyou/voice_api.go index a32410f..66c3731 100644 --- a/fakeyou/voice_api.go +++ b/fakeyou/voice_api.go @@ -2,6 +2,9 @@ package fakeyou import ( "encoding/json" + "fmt" + + "gopkg.in/validator.v2" "github.com/Allan-Nava/fakeyou.go/constants/routes" ) @@ -42,3 +45,34 @@ func (f *fakeyou) GetListOfVoiceCategories() (*ResponseVoiceCategories, error) { } return &obj, nil } + +/* + +Generate TTS Audio +Make a TTS request +To turn text into speech with your desired voice, you'll need to find the appropriate TTS model token from the model lookup API. + +For example, TM:7wbtjphx8h8v in the following examples is our Mario * voice. (A paid voice actor that we hired to impersonate Mario). +*/ + +func (f *fakeyou) GenerateTTSAudio(text string, ttsModelToken string) (*ResponseGenerateTTS, error) { + // + body := &RequestGenerateTTS{ + TTSModelToken: ttsModelToken, + InferenceText: text, + //UUIDIdempotencyToken: uuid, + } + if errs := validator.Validate(body); errs != nil { + // values not valid, deal with errors here + return nil, errs + } + // + resp, err := f.restyPost(routes.LOGIN, body) + if err != nil { + return nil, err + } + if resp.StatusCode() == 429 { + return nil, fmt.Errorf("IP IS BANNED (caused by login request)") + } + return nil, fmt.Errorf("") +}