Skip to content

Can I also stream the played sound to a file? #169

@dhairya0904

Description

@dhairya0904

Hi

I have a use case where I want to play the sound and also stream this to file to play it again.

package main

import (
	"log"
	"os"
	"time"

	"github.com/faiface/beep"
	"github.com/faiface/beep/mp3"
	"github.com/faiface/beep/speaker"
)

func main() {

	s1 := getStream("./Lame_Drivers_-_01_-_Frozen_Egg.mp3")
	s2 := getStream("./Miami_Slice_-_04_-_Step_Into_Me.mp3")

	defer s1.Close()
	defer s2.Close()

	speaker.Init(48000, 2048)
	mixer := &beep.Mixer{}
	// done := make(chan bool)
	speaker.Play(mixer)

	mixer.Add(s1)
	mixer.Add(s2)

	time.Sleep(2 * time.Minute)
}

func getStream(file string) beep.StreamSeekCloser {
	f, err := os.Open(file)
	if err != nil {
		log.Fatal(err)
	}

	streamer, _, err := mp3.Decode(f)
	if err != nil {
		log.Fatal(err)
	}

	return streamer
}

I want this sound to be saved in a file, such that I can play the entire stream again.
Can anyone please help me with this?
Any help is appreciated

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions