This commit is contained in:
2023-04-18 17:40:43 -07:00
parent ae310cc85e
commit 356266b818
4 changed files with 27 additions and 21 deletions

View File

@@ -13,8 +13,8 @@ import (
"github.com/taigrr/elevenlabs/client/types"
)
func (c Client) HistoryDelete(ctx context.Context, historyItemId string) (bool, error) {
url := fmt.Sprintf(c.endpoint+"/v1/history/%s", historyItemId)
func (c Client) HistoryDelete(ctx context.Context, historyItemID string) (bool, error) {
url := fmt.Sprintf(c.endpoint+"/v1/history/%s", historyItemID)
client := &http.Client{}
req, err := http.NewRequestWithContext(ctx, http.MethodDelete, url, nil)
@@ -47,7 +47,6 @@ func (c Client) HistoryDelete(ctx context.Context, historyItemId string) (bool,
default:
return false, errors.Join(err, ErrUnspecified)
}
return true, nil
}
func (c Client) HistoryDownloadZipWriter(ctx context.Context, w io.Writer, id1, id2 string, additionalIDs ...string) error {
@@ -273,10 +272,10 @@ func (c Client) GetHistoryIDs(ctx context.Context, voiceIDs ...string) ([]string
}
for _, i := range items {
if len(voiceIDs) == 0 {
ids = append(ids, i.HistoryItemId)
ids = append(ids, i.HistoryItemID)
} else {
if _, ok := voiceMap[i.VoiceId]; ok {
ids = append(ids, i.HistoryItemId)
if _, ok := voiceMap[i.VoiceID]; ok {
ids = append(ids, i.HistoryItemID)
}
}
}

View File

@@ -100,7 +100,7 @@ func (c Client) TTS(ctx context.Context, w io.Writer, text, voiceID string, opti
}
}
func (c Client) TextToSpeechV1TextToSpeechVoiceIdStreamPost(ctx context.Context, w io.Writer, text, voiceID string, options types.SynthesisOptions) error {
func (c Client) TTSStream(ctx context.Context, w io.Writer, text, voiceID string, options types.SynthesisOptions) error {
url := fmt.Sprintf(c.endpoint+"/v1/text-to-speech/%s/stream", voiceID)
opts := types.TTS{
Text: text,

View File

@@ -73,9 +73,9 @@ type GetVoicesResponseModel struct {
Voices []VoiceResponseModel `json:"voices"`
}
type HistoryItemList struct {
HistoryItemId string `json:"history_item_id"`
RequestId string `json:"request_id"`
VoiceId string `json:"voice_id"`
HistoryItemID string `json:"history_item_id"`
RequestID string `json:"request_id"`
VoiceID string `json:"voice_id"`
VoiceName string `json:"voice_name"`
Text string `json:"text"`
DateUnix int32 `json:"date_unix"`
@@ -95,14 +95,14 @@ type LanguageResponseModel struct {
DisplayName string `json:"display_name"`
}
type RecordingResponseModel struct {
RecordingId string `json:"recording_id"`
RecordingID string `json:"recording_id"`
MimeType string `json:"mime_type"`
SizeBytes int32 `json:"size_bytes"`
UploadDateUnix int32 `json:"upload_date_unix"`
Transcription string `json:"transcription"`
}
type Sample struct {
SampleId string `json:"sample_id"`
SampleID string `json:"sample_id"`
FileName string `json:"file_name"`
MimeType string `json:"mime_type"`
SizeBytes int32 `json:"size_bytes"`
@@ -127,7 +127,7 @@ type Subscription struct {
Status string `json:"status"`
}
type TtsModelResponseModel struct {
ModelId string `json:"model_id"`
ModelID string `json:"model_id"`
DisplayName string `json:"display_name"`
SupportedLanguage []LanguageResponseModel `json:"supported_language"`
}
@@ -155,14 +155,14 @@ type VerificationAttemptResponseModel struct {
Recording *RecordingResponseModel `json:"recording"`
}
type VoiceResponseModel struct {
VoiceId string `json:"voice_id"`
VoiceID string `json:"voice_id"`
Name string `json:"name"`
Samples []Sample `json:"samples"`
Category string `json:"category"`
FineTuning FineTuningResponseModel `json:"fine_tuning"`
Labels map[string]string `json:"labels"`
Description string `json:"description"`
PreviewUrl string `json:"preview_url"`
PreviewURL string `json:"preview_url"`
AvailableForTiers []string `json:"available_for_tiers"`
Settings SynthesisOptions `json:"settings"`
}

View File

@@ -243,7 +243,7 @@ func (c Client) GetVoice(ctx context.Context, voiceID string) (types.VoiceRespon
client := &http.Client{}
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
if err != nil {
return err
return types.VoiceResponseModel{}, err
}
req.Header.Set("xi-api-key", c.apiKey)
req.Header.Set("User-Agent", "github.com/taigrr/elevenlabs")
@@ -259,16 +259,23 @@ func (c Client) GetVoice(ctx context.Context, voiceID string) (types.VoiceRespon
} else {
err = errors.Join(err, ve)
}
return err
return types.VoiceResponseModel{}, err
case 401:
return ErrUnauthorized
return types.VoiceResponseModel{}, ErrUnauthorized
case 200:
if err != nil {
return err
return types.VoiceResponseModel{}, err
}
return nil
vrm := types.VoiceResponseModel{}
defer res.Body.Close()
jerr := json.NewDecoder(res.Body).Decode(&vrm)
if jerr != nil {
return types.VoiceResponseModel{}, jerr
}
return vrm, nil
default:
return errors.Join(err, ErrUnspecified)
return types.VoiceResponseModel{}, errors.Join(err, ErrUnspecified)
}
}