I have a mobile app built with React Native that sends recorded audio files to my AWS Lambda backend function (written in Go). The audio gets sent as multipart form data but I’m having trouble reading it properly on the server side.
For recording, I use react-native-audio-recorder-player
with these settings:
const recordingConfig: RecordingConfig = {
AudioEncoderAndroid: AudioEncoderAndroidType.AAC,
AudioSourceAndroid: AudioSourceAndroidType.MIC,
AVModeIOS: AVModeIOSOption.measurement,
AVEncoderAudioQualityKeyIOS: AVEncoderAudioQualityIOSType.high,
AVNumberOfChannelsKeyIOS: 2,
AVFormatIDKeyIOS: AVEncodingOption.wav,
};
On the client side, I create the form data like this:
const uploadData = new FormData();
uploadData.append('audioFile', {
uri: recordingPath,
type: 'audio/wav',
name: 'recording.wav',
});
My Lambda function tries to process the audio data (I have BinaryMediaTypes configured in my SAM template):
audioReader := strings.NewReader(event.Body)
openaiClient := openai.NewClient(
option.WithAPIKey(API_KEY),
)
transcription, err := openaiClient.Audio.Transcriptions.New(context.Background(), openai.AudioTranscriptionNewParams{
Model: openai.F(openai.AudioModelWhisper1),
File: openai.FileParam(audioReader, "recording.wav", "audio/wav"),
})
if err != nil {
log.Error("Transcription failed", zap.Error(err))
return "", err
}
The issue is that my audioReader appears empty when I log it. The OpenAI API responds with an invalid file format error even though WAV should be supported. How can I properly extract the audio file from the multipart form data in my Go Lambda function?