admin管理员组文章数量:1303389
I'm building a react native app that pass as form data an audio registration to a backend lambda function written in golang.
I'm using react-native-audio-recorder-player
:
const audioSet: AudioSet = {
AudioEncoderAndroid: AudioEncoderAndroidType.AAC,
AudioSourceAndroid: AudioSourceAndroidType.MIC,
AVModeIOS: AVModeIOSOption.measurement,
AVEncoderAudioQualityKeyIOS: AVEncoderAudioQualityIOSType.high,
AVNumberOfChannelsKeyIOS: 2,
AVFormatIDKeyIOS: AVEncodingOption.wav,
};
This is the form data in the frontend:
formData.append('file', {
uri: audioFilePath,
type: 'audio/wav',
name: 'audio.wav',
});
This is the backend code, keep in mind that I have setup the BinaryMediaTypes in the APi gateway parameters in the template.yaml
, so the request.Body
actually exists.
This is the openai library:
fileReader := strings.NewReader(request.body)
client := openai.NewClient(
option.WithAPIKey(OPEN_AI_KEY),
)
response, err := client.Audio.Transcriptions.New(context.Background(), openai.AudioTranscriptionNewParams{
Model: openai.F(openai.AudioModelWhisper1),
File: openai.FileParam(fileReader, "audio.wav", "audio/wav"),
})
if err != nil {
logger.Error("Error transcribing audio", zap.Error(err))
return "", err
}
The problem seems to be related to the fileReader since if I print it this is the result:
{
"level": "info",
"ts": 1739222783.0462933,
"caller": "openai/transcribe.go:18",
"msg": "Transcribing audio",
"fileReader": {}
}
Thereby the open ai api return the following error:
"error": "POST \"\": 400 Bad Request {\n \"error\": {\n \"message\": \"Invalid file format. Supported formats: ['flac', 'm4a', 'mp3', 'mp4', 'mpeg', 'mpga', 'oga', 'ogg', 'wav', 'webm']\",\n \"type\": \"invalid_request_error\",\n \"param\": null,\n \"code\": null\n }\n}"
Thank you
本文标签: goLambda function read audio file coming from frontend as form dataStack Overflow
版权声明:本文标题:go - Lambda function read audio file coming from frontend as form data - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741689454a2392636.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论