Storing WAV recording to disk plays as static

I'm recording voice via jquery then sending it to django view:

views.py

    ...

    elif voice_value:
        #get voice
        voice_value = request.FILES.get('sound_file.wav')
        #read as bytes
        file_content_bytes = voice_value.read()

        #using pydub
        audio_bytes = file_content_bytes # Replace with your actual audio data
        audio_segment = AudioSegment(
            data=audio_bytes,
            sample_width=2,  # Example: 2 bytes per sample (16-bit audio)
            frame_rate=48000, # Example: 44.1 kHz sample rate
            channels=1       # Example: Mono audio
        )
        audio_segment.export("output_1.wav", format="wav")

        data = {'payload':'anything'}
        return JsonResponse(data,safe=False)

It produces the output as a wav file, but it's distorted and just static when played. I should say that the parameters (channels,sample_width,framerate) are the default.

What seems to be the problem ?

Вернуться на верх