| package audioflow |
|
|
| import ( |
| chatgptrequestconverter "aurora/conversion/requests/chatgpt" |
| "aurora/httpclient" |
| "aurora/internal/chatgpt" |
| "aurora/internal/accounts" |
| chatgpt_types "aurora/typings/chatgpt" |
| "fmt" |
| "net/http" |
| ) |
|
|
| |
| var TTSFormatMap = map[string]string{ |
| "mp3": "mp3", |
| "opus": "opus", |
| "aac": "aac", |
| "flac": "aac", |
| "wav": "aac", |
| "pcm": "aac", |
| } |
|
|
| |
| var TTSTypeMap = map[string]string{ |
| "mp3": "audio/mpeg", |
| "opus": "audio/ogg", |
| "aac": "audio/aac", |
| } |
|
|
| |
| var TTSVoiceMap = map[string]string{ |
| "alloy": "cove", |
| "ash": "fathom", |
| "coral": "vale", |
| "echo": "ember", |
| "fable": "breeze", |
| "onyx": "orbit", |
| "nova": "maple", |
| "sage": "glimmer", |
| "shimmer": "juniper", |
| } |
|
|
| |
| type SynthesizeResult struct { |
| Data []byte |
| ContentType string |
| } |
|
|
| |
| func Synthesize(client interface{ SetProxy(string); SetCookies(string, interface{}) }, account *accounts.Account, input, voice, format, proxyURL string) (*SynthesizeResult, int, error) { |
| if account == nil || account.Token == "" || account.Type == accounts.TypeNoAuth { |
| return nil, http.StatusBadRequest, fmt.Errorf("TTS requires a logged-in ChatGPT access token") |
| } |
|
|
| translatedRequest := chatgptrequestconverter.ConvertTTSAPIRequest(input) |
| clientState := chatgpt.NewChatClientState() |
| clientState.ConversationID = translatedRequest.ConversationID |
| clientState.ParentMessageID = translatedRequest.ParentMessageID |
|
|
| |
| _, status, err := postConversationForTTS(client, account, translatedRequest, proxyURL, clientState) |
| if err != nil { |
| return nil, status, err |
| } |
|
|
| return nil, http.StatusOK, nil |
| } |
|
|
| |
| type TranscribeResult struct { |
| Text string |
| } |
|
|
| |
| func Transcribe(client httpclient.AuroraHttpClient, account *accounts.Account, proxyURL string, audioData []byte, filename, mimeType, language string) (*TranscribeResult, int, error) { |
| if account == nil || account.Token == "" || account.Type == accounts.TypeNoAuth { |
| return nil, http.StatusBadRequest, fmt.Errorf("audio transcription requires a logged-in ChatGPT access token") |
| } |
| if len(audioData) == 0 { |
| return nil, http.StatusBadRequest, fmt.Errorf("empty audio data") |
| } |
|
|
| text, status, err := chatgpt.TranscribeAudio(client, account, proxyURL, audioData, filename, mimeType, language) |
| if err != nil { |
| return nil, status, err |
| } |
| return &TranscribeResult{Text: text}, status, nil |
| } |
|
|
| |
| func NormalizeFormat(format string) string { |
| if f := TTSFormatMap[format]; f != "" { |
| return f |
| } |
| return "aac" |
| } |
|
|
| |
| func NormalizeVoice(voice string) string { |
| if v := TTSVoiceMap[voice]; v != "" { |
| return v |
| } |
| return "cove" |
| } |
|
|
| |
| func ContentTypeForFormat(format string) string { |
| if ct := TTSTypeMap[format]; ct != "" { |
| return ct |
| } |
| return "audio/aac" |
| } |
|
|
| |
| var SupportedTranscriptionFormats = map[string]string{ |
| "json": "application/json", |
| "text": "text/plain", |
| "verbose_json": "application/json", |
| } |
|
|
| |
| func ValidateTranscriptionFormat(format string) (string, bool) { |
| ct, ok := SupportedTranscriptionFormats[format] |
| return ct, ok |
| } |
|
|
| func postConversationForTTS(client interface{}, account *accounts.Account, req chatgpt_types.ChatGPTRequest, proxyURL string, state *chatgpt.ChatClientState) (*http.Response, int, error) { |
| |
| |
| return nil, http.StatusOK, nil |
| } |
|
|