Open mcondie-addsalt opened 3 weeks ago
@mcondie-addsalt no, audio package has no external dependencies. Seems like your wav reader is nil, Check did you handle all your errors. If all ok send me full code then
Here's the entire code file.
// SPDX-License-Identifier: MPL-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024, Emir Aganovic
package main
import (
"context"
"os"
"os/signal"
"time"
"github.com/emiago/diago"
"github.com/emiago/diago/media"
"github.com/emiago/diago/testdata"
"github.com/emiago/sipgo"
"github.com/emiago/sipgo/sip"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
)
// Dial this app with
// gophone dial -media=speaker "sip:123@127.0.0.1"
func main() {
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt)
defer cancel()
lev, err := zerolog.ParseLevel(os.Getenv("LOG_LEVEL"))
if err != nil || lev == zerolog.NoLevel {
lev = zerolog.InfoLevel
}
zerolog.TimeFieldFormat = zerolog.TimeFormatUnixMicro
log.Logger = zerolog.New(zerolog.ConsoleWriter{
Out: os.Stdout,
TimeFormat: time.StampMicro,
}).With().Timestamp().Logger().Level(lev)
sip.SIPDebug = os.Getenv("SIP_DEBUG") == "true"
media.RTCPDebug = os.Getenv("RTCP_DEBUG") == "true"
err = start(ctx)
if err != nil {
log.Fatal().Err(err).Msg("PBX finished with error")
}
}
func start(ctx context.Context) error {
ua, _ := sipgo.NewUA()
transportTCP := diago.Transport{
Transport: "udp",
BindHost: "0.0.0.0",
BindPort: 5060,
}
tu := diago.NewDiago(ua,
diago.WithTransport(transportTCP),
)
return tu.Serve(ctx, func(inDialog *diago.DialogServerSession) {
log.Info().Str("id", inDialog.ID).Msg("New dialog request")
defer log.Info().Str("id", inDialog.ID).Msg("Dialog finished")
Playback(inDialog)
})
}
func Playback(inDialog *diago.DialogServerSession) error {
inDialog.Progress() // Progress -> 100 Trying
inDialog.Ringing() // Ringing -> 180 Response
inDialog.Answer() // Answer -> 200 Response
playfile, _ := testdata.OpenFile("echo-test.wav")
log.Info().Str("file", "echo-test.wav").Msg("Playing a file")
pb, err := inDialog.PlaybackCreate()
if err != nil {
return err
}
_, err = pb.Play(playfile, "audio/wav")
return err
}
I've tried this on a plain GCP vm as well as running in an ubuntu vm (v24) locally and I get the same result.
I'm getting a segfault when attempting a basic wav file playback. Are there dependencies that need to be installed on a debian/ubuntu server to support audio processing?