Closed grokify closed 1 year ago
wav := NewEncoder(f, 8000, 8, 1, 1)
The problem lies with the last argument.
TL;DR:
Change it to:
wav := NewEncoder(f, 8000, 8, 1, 7)
Details:
WAV format allows storage of audio data in various encodings, such as raw data, compressed formats, etc. Therefore, you should explicitly set the µ-law compression format in the header. This ensures that media players recognize and play back the audio correctly.
In your example, passing "1" means "uncompressed pulse code modulated samples." This is incorrect since your data is actually encoded in a different, compressed format.
Although the original author of the issue may no longer need assistance due to the passage of time, I thought it would be helpful to present the solution for future readers.
I also suggest closing this issue. @mattetti
FWIW for my use-case encoding the Twilio Stream websocket audio/x-mulaw
on my local M2 Mac,
I had to have different encoder params, than the input ones (otherwise ended up 2x slower)
inputBuffer := &audio.IntBuffer{
Data: intData,
Format: &audio.Format{
SampleRate: 8000,
NumChannels: 1,
},
SourceBitDepth: 8,
}
// When using (f, 8000, 8, 1, 7), it ended up 2x slower idk why
wav := NewEncoder(f, 16000, 16, 1, 7)
wav := NewEncoder(f, 8000, 8, 1, 1)
The problem lies with the last argument.
TL;DR: Change it to:
wav := NewEncoder(f, 8000, 8, 1, 7)
Details:
WAV format allows storage of audio data in various encodings, such as raw data, compressed formats, etc. Therefore, you should explicitly set the µ-law compression format in the header. This ensures that media players recognize and play back the audio correctly.
In your example, passing "1" means "uncompressed pulse code modulated samples." This is incorrect since your data is actually encoded in a different, compressed format.
Although the original author of the issue may no longer need assistance due to the passage of time, I thought it would be helpful to present the solution for future readers.
I also suggest closing this issue. @mattetti
it works a WavAudioFormat value of 6 or 7 would indicate that the audio data is stored in the A-law or μ-law format, which are forms of compressed PCM commonly used in telephony.
Issue
I have a 8Khz 8-bit PCM ulaw byte slice that I would like to convert to a WAV file. When I try to convert it using this library, I get audio that is loud and choppy, sounding a bit like the following issue.
https://github.com/go-audio/audio/issues/16
I'm using an
Encoder
as follows:I'm not quite sure how to convert the raw byte slice into an
audio.IntBuffer
so I'm doing the following, which results in the poor quality audio.Any tips on how to get this library to work for this?
Alternative 1 - Works
As an alternative, the following raw approach results in good sounding audio where I can write out the bytes without transformation.
I've added this here for easy reuse:
https://github.com/grokify/simplego/blob/master/audio/ulaw/ulaw.go
Alternative 2 - Works