Converting mp3 files to wav in golang

Viewed 544

I'm trying to convert an MP3 file to Wav using GStreamer in go.

package main

import (
    "fmt"
    "os"
    "time"

    "github.com/notedit/gst"
)

func main() {
    pipeline, err := gst.ParseLaunch("appsrc name=mysource ! decodebin ! audioresample ! audioconvert ! audio/x-raw,format=S16LE,rate=16000 ! wavenc ! filesink location=/tmp/out.wav")

    if err != nil {
        panic("pipeline error")
    }

    bytes, _ := os.ReadFile("/tmp/a.mp3")
    pipeline.SetState(gst.StatePlaying)
    element := pipeline.GetByName("mysource")

    time.Sleep(2 * time.Second)
    err = element.PushBuffer(bytes)

    if err != nil {
        fmt.Println("push buffer error")
    }

    pipeline.SetState(gst.StateNull)

    pipeline = nil
    element = nil
}

But the output file is empty. Even this simple pipeline results an empty output file:

pipeline, err := gst.ParseLaunch("appsrc name=mysource ! filesink location=/tmp/out.wav")
0 Answers
Related