Skip to content

Commit 4d86d02

Browse files
authored
feat: support Azure OpenAI TTS. (songquanpeng#1177)
1 parent 7a44adb commit 4d86d02

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

relay/controller/audio.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,15 @@ func RelayAudioHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
104104
}
105105

106106
fullRequestURL := util.GetFullRequestURL(baseURL, requestURL, channelType)
107-
if relayMode == constant.RelayModeAudioTranscription && channelType == common.ChannelTypeAzure {
108-
// https://learn.microsoft.com/en-us/azure/ai-services/openai/whisper-quickstart?tabs=command-line#rest-api
107+
if channelType == common.ChannelTypeAzure {
109108
apiVersion := util.GetAzureAPIVersion(c)
110-
fullRequestURL = fmt.Sprintf("%s/openai/deployments/%s/audio/transcriptions?api-version=%s", baseURL, audioModel, apiVersion)
109+
if relayMode == constant.RelayModeAudioTranscription {
110+
// https://learn.microsoft.com/en-us/azure/ai-services/openai/whisper-quickstart?tabs=command-line#rest-api
111+
fullRequestURL = fmt.Sprintf("%s/openai/deployments/%s/audio/transcriptions?api-version=%s", baseURL, audioModel, apiVersion)
112+
} else if relayMode == constant.RelayModeAudioSpeech {
113+
// https://learn.microsoft.com/en-us/azure/ai-services/openai/text-to-speech-quickstart?tabs=command-line#rest-api
114+
fullRequestURL = fmt.Sprintf("%s/openai/deployments/%s/audio/speech?api-version=%s", baseURL, audioModel, apiVersion)
115+
}
111116
}
112117

113118
requestBody := &bytes.Buffer{}
@@ -123,7 +128,7 @@ func RelayAudioHelper(c *gin.Context, relayMode int) *relaymodel.ErrorWithStatus
123128
return openai.ErrorWrapper(err, "new_request_failed", http.StatusInternalServerError)
124129
}
125130

126-
if relayMode == constant.RelayModeAudioTranscription && channelType == common.ChannelTypeAzure {
131+
if (relayMode == constant.RelayModeAudioTranscription || relayMode == constant.RelayModeAudioSpeech) && channelType == common.ChannelTypeAzure {
127132
// https://learn.microsoft.com/en-us/azure/ai-services/openai/whisper-quickstart?tabs=command-line#rest-api
128133
apiKey := c.Request.Header.Get("Authorization")
129134
apiKey = strings.TrimPrefix(apiKey, "Bearer ")

0 commit comments

Comments
 (0)