1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-27 17:23:00 +00:00

examples/voice: Fix build error

This commit is contained in:
diamondburned 2023-11-04 01:49:41 -07:00
parent 093436066e
commit 5ebd28bab6
No known key found for this signature in database
GPG key ID: D78C4471CE776659

View file

@ -4,6 +4,7 @@ import (
"context" "context"
"errors" "errors"
"flag" "flag"
"fmt"
"log" "log"
"os" "os"
"os/exec" "os/exec"
@ -61,7 +62,7 @@ const (
func start(ctx context.Context, s *state.State, id discord.ChannelID, file string) error { func start(ctx context.Context, s *state.State, id discord.ChannelID, file string) error {
v, err := voice.NewSession(s) v, err := voice.NewSession(s)
if err != nil { if err != nil {
return errors.Wrap(err, "cannot make new voice session") return fmt.Errorf("cannot make new voice session: %w", err)
} }
// Optimize Opus frame duration. This step is optional, but it is // Optimize Opus frame duration. This step is optional, but it is
@ -97,30 +98,30 @@ func start(ctx context.Context, s *state.State, id discord.ChannelID, file strin
stdout, err := ffmpeg.StdoutPipe() stdout, err := ffmpeg.StdoutPipe()
if err != nil { if err != nil {
return errors.Wrap(err, "failed to get stdout pipe") return fmt.Errorf("failed to get stdout pipe: %w", err)
} }
// Kickstart FFmpeg before we join. FFmpeg will wait until we start // Kickstart FFmpeg before we join. FFmpeg will wait until we start
// consuming the stream to process further. // consuming the stream to process further.
if err := ffmpeg.Start(); err != nil { if err := ffmpeg.Start(); err != nil {
return errors.Wrap(err, "failed to start ffmpeg") return fmt.Errorf("failed to start ffmpeg: %w", err)
} }
// Join the voice channel. // Join the voice channel.
if err := v.JoinChannelAndSpeak(ctx, id, false, true); err != nil { if err := v.JoinChannelAndSpeak(ctx, id, false, true); err != nil {
return errors.Wrap(err, "failed to join channel") return fmt.Errorf("failed to join channel: %w", err)
} }
defer v.Leave(ctx) defer v.Leave(ctx)
// Start decoding FFmpeg's OGG-container output and extract the raw Opus // Start decoding FFmpeg's OGG-container output and extract the raw Opus
// frames into the stream. // frames into the stream.
if err := oggreader.DecodeBuffered(v, stdout); err != nil { if err := oggreader.DecodeBuffered(v, stdout); err != nil {
return errors.Wrap(err, "failed to decode ogg") return fmt.Errorf("failed to decode ogg: %w", err)
} }
// Wait until FFmpeg finishes writing entirely and leave. // Wait until FFmpeg finishes writing entirely and leave.
if err := ffmpeg.Wait(); err != nil { if err := ffmpeg.Wait(); err != nil {
return errors.Wrap(err, "failed to finish ffmpeg") return fmt.Errorf("failed to finish ffmpeg: %w", err)
} }
return nil return nil