@@ -2,7 +2,6 @@ package openai
22
33import (
44 "context"
5- "errors"
65 "net/http"
76)
87
@@ -36,11 +35,6 @@ const (
3635 SpeechResponseFormatPcm SpeechResponseFormat = "pcm"
3736)
3837
39- var (
40- ErrInvalidSpeechModel = errors .New ("invalid speech model" )
41- ErrInvalidVoice = errors .New ("invalid voice" )
42- )
43-
4438type CreateSpeechRequest struct {
4539 Model SpeechModel `json:"model"`
4640 Input string `json:"input"`
@@ -49,32 +43,7 @@ type CreateSpeechRequest struct {
4943 Speed float64 `json:"speed,omitempty"` // Optional, default to 1.0
5044}
5145
52- func contains [T comparable ](s []T , e T ) bool {
53- for _ , v := range s {
54- if v == e {
55- return true
56- }
57- }
58- return false
59- }
60-
61- func isValidSpeechModel (model SpeechModel ) bool {
62- return contains ([]SpeechModel {TTSModel1 , TTSModel1HD , TTSModelCanary }, model )
63- }
64-
65- func isValidVoice (voice SpeechVoice ) bool {
66- return contains ([]SpeechVoice {VoiceAlloy , VoiceEcho , VoiceFable , VoiceOnyx , VoiceNova , VoiceShimmer }, voice )
67- }
68-
6946func (c * Client ) CreateSpeech (ctx context.Context , request CreateSpeechRequest ) (response RawResponse , err error ) {
70- if ! isValidSpeechModel (request .Model ) {
71- err = ErrInvalidSpeechModel
72- return
73- }
74- if ! isValidVoice (request .Voice ) {
75- err = ErrInvalidVoice
76- return
77- }
7847 req , err := c .newRequest (ctx , http .MethodPost , c .fullURL ("/audio/speech" , string (request .Model )),
7948 withBody (request ),
8049 withContentType ("application/json" ),
0 commit comments