Skip to content

Commit

Permalink
Updated the audio IO package.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Bruse committed May 3, 2024
1 parent 675bc12 commit 645cfd1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion go/aio/aio.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ func Fetch(path string, dir string) (string, error) {

// Load loads audio from an ffmpeg-decodable file from a path (which may be a URL).
func Load(path string) (*audio.Audio, error) {
cmd := exec.Command("ffmpeg", "-i", path, "-vn", "-acodec", "pcm_s16le", "-f", "wav", "-ar", "48000", "-")
return LoadAtRate(path, 48000)
}

// Load loads audio from an ffmpeg-decodable file from a path (which may be a URL) and returns it at the given sample rate.
func LoadAtRate(path string, rate int) (*audio.Audio, error) {
cmd := exec.Command("ffmpeg", "-i", path, "-vn", "-acodec", "pcm_s16le", "-f", "wav", "-ar", fmt.Sprint(rate), "-")
stdout, stderr := &bytes.Buffer{}, &bytes.Buffer{}
cmd.Stdout, cmd.Stderr = stdout, stderr
if err := cmd.Run(); err != nil {
Expand Down

0 comments on commit 645cfd1

Please sign in to comment.