π΅ wav2g729 - WAV to G.729 Transcoder
10K+
Federico Pereira [email protected]β
Audio transcoder from WAV format to G.729 using the bcg729β library from Go via CGO.
This project provides a command-line tool that converts audio files from WAV (PCM) format to G.729 encoded files. The G.729 codec is widely used in VoIP telephony for its excellent voice quality to compression ratio.
libbcg729 libraryCGO_ENABLED=1)libbcg729 installed on the systemThe image is publicly available on Docker Hub as cnsoluciones/wav2g729:latest. You don't need to build the image locally.
docker run --rm -v $PWD:/work cnsoluciones/wav2g729:latest input.wav output.g729
Command explanation:
docker run: Runs a container from the image--rm: Automatically removes the container after execution-v $PWD:/work: Mounts the current directory to /work inside the containercnsoluciones/wav2g729:latest: Public Docker Hub imageinput.wav: Input file (WAV)output.g729: Output file (G.729 raw bitstream)docker build -t wav2g729:latest .
This command:
bcg729 library from source code# Show complete help
docker run --rm cnsoluciones/wav2g729:latest --help
# Show version
docker run --rm cnsoluciones/wav2g729:latest --version
# Or simply run without arguments
docker run --rm cnsoluciones/wav2g729:latest
The helper includes (in English):
docker run --rm -v /path/to/your/files:/work cnsoluciones/wav2g729:latest audio.wav audio.g729
To validate that the .g729 file was created correctly, you can convert it back to WAV with FFmpeg:
ffmpeg -f g729 -i output.g729 -ar 8000 -ac 1 -c:a pcm_s16le output.wav
Command explanation:
-f g729: Specifies input format as G.729 raw bitstream-i output.g729: Input file (the generated G.729)-ar 8000: Output sample rate (8000 Hz)-ac 1: Number of output channels (1 = mono)-c:a pcm_s16le: Output audio codec (PCM 16-bit little-endian)output.wav: Resulting WAV fileNow you can play output.wav with any audio player to verify the conversion quality. If you hear the audio correctly, the conversion was successful! π΅
.
βββ Dockerfile # Multi-stage Docker image definition
βββ go.mod # Go project dependencies
βββ go.sum # Dependency checksums
βββ transcoding.go # Main transcoder code
βββ README.md # This file (English)
βββ README.es.md # Spanish documentation
The project uses a two-stage Dockerfile optimized with Alpine Linux:
Stage 1 (build): Image based on golang:1.23-alpine
bcg729 as shared library (libbcg729.so)Stage 2 (runtime): Image based on alpine:latest
libbcg729.so and minimal dependencieslibbcg729.so instead of staticca-certificates and libc6-compatThe program uses CGO to call C functions from libbcg729:
/*
#cgo CFLAGS: -I/usr/local/include
#cgo LDFLAGS: -L/usr/local/lib -lbcg729 -Wl,-rpath,/usr/local/lib
#include <bcg729/encoder.h>
*/
import "C"
Conversion process:
github.com/youpy/go-wavbcg729EncoderThe program includes a complete helper that activates when:
docker run --rm cnsoluciones/wav2g729:latestdocker run --rm cnsoluciones/wav2g729:latest --helpHelper features (in English):
The program automatically validates that the WAV file meets the requirements:
β
AudioFormat = 1 (PCM)
β
NumChannels = 1 (Mono)
β
SampleRate = 8000 Hz
β
BitsPerSample = 16
If your file doesn't meet these requirements, you can convert it with FFmpeg:
# Convert any audio file to compatible format
ffmpeg -i input.mp3 -ar 8000 -ac 1 -sample_fmt s16 -acodec pcm_s16le output.wav
If you prefer to compile locally without Docker:
git clone https://github.com/BelledonneCommunications/bcg729
cd bcg729
cmake -S . -B build
cmake --build build --target install
sudo ldconfig
export CGO_ENABLED=1
go build -o transcoding transcoding.go
./transcoding input.wav output.g729
The encoder is configured with VAD disabled (enableVAD = 0):
You can modify this configuration in transcoding.go line 19.
Your file is in compressed format. Convert it with FFmpeg:
ffmpeg -i file.wav -acodec pcm_s16le output.wav
Your file is stereo. Convert to mono:
ffmpeg -i file.wav -ac 1 output.wav
Change the sample rate:
ffmpeg -i file.wav -ar 8000 output.wav
Adjust the sample format:
ffmpeg -i file.wav -sample_fmt s16 output.wav
ffmpeg -i input.mp3 -ar 8000 -ac 1 -sample_fmt s16 -acodec pcm_s16le output.wav
.g729 file is a raw bitstream without containerffmpeg -f g729 -i output.g729 -ar 8000 -ac 1 -c:a pcm_s16le output.wav to convert G.729 to WAVbcg729 is an open-source and royalty-free implementationThis project uses bcg729 which is under BSD-like license. Check license terms before using in production.
Contributions are welcome. Please:
git checkout -b feature/AmazingFeature)git commit -m 'Add some AmazingFeature')git push origin feature/AmazingFeature)Federico Pereira [email protected]β GIT https://github.com/lordbasex/golang-examples/tree/main/wav2g729β
WAV to G.729 audio conversion project using Go and CGO.
This project is part of CNSoluciones, specialized in telecommunications and VoIP solutions.
Questions or issues? Open an issue in the repository.
Content type
Image
Digest
sha256:8db3215b1β¦
Size
5.4 MB
Last updated
11 months ago
docker pull cnsoluciones/wav2g729