MarkKremer / microphone

A microphone input stream for the faiface/beep library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Example not compiling due to type miss match

a-hilaly opened this issue · comments

commented

Hi @MarkKremer - thanks for the package! I tried to run the example you built here , but i'm running into type miss match issues on line 65. I tried to manually build the write type

	err = wav.Encode(f, stream, beep.Format{
		SampleRate:  beep.SampleRate(format.SampleRate),
		NumChannels: format.NumChannels,
		Precision:   format.Precision,
	})

But still hitting a 2023/11/05 19:38:40 Sample format not supported error. Any guidance on this issue? Thanks again.

Hi Amine,

We've forked the Beep repository to https://github.com/gopxl/beep because the old repository is not maintained. I think you may be using faiface's repo still and are getting the type mismatch because of that. If not, could you provide me with the error message?

For the sample format error, could you run the following test program and reply with the output:

package main

import (
	"fmt"

	"github.com/gordonklaus/portaudio"
)

func main() {
	err := portaudio.Initialize()
	if err != nil {
		panic(err)
	}

	fmt.Println("Defauld device:")
	defaultDevice, err := portaudio.DefaultInputDevice()
	if err != nil {
		panic(err)
	}
	printDevice(defaultDevice)

	fmt.Println("Stream parameters:")
	params := portaudio.HighLatencyParameters(defaultDevice, nil)
	fmt.Printf("  SampleRate: %f\n", params.SampleRate)
	fmt.Printf("  FramesPerBuffer: %d\n", params.FramesPerBuffer)
	fmt.Printf("  Flags: %d\n", params.Flags)
	fmt.Printf("  Input.Channels: %d\n", params.Input.Channels)
	fmt.Printf("  Input.Latency: %s\n", params.Input.Latency)

	bufF32 := make([][]float32, 1)
	bufF32[0] = make([]float32, 512)
	fmt.Printf("  IsFormatSupported(1 channel, float32) err: %v\n", portaudio.IsFormatSupported(params, bufF32))
	bufF32 = make([][]float32, 2)
	bufF32[0] = make([]float32, 512)
	bufF32[1] = make([]float32, 512)
	fmt.Printf("  IsFormatSupported(2 channels, float32) err: %v\n", portaudio.IsFormatSupported(params, bufF32))

	bufI32 := make([][]int32, 1)
	bufI32[0] = make([]int32, 512)
	fmt.Printf("  IsFormatSupported(1 channel, int32) err: %v\n", portaudio.IsFormatSupported(params, bufI32))
	bufI32 = make([][]int32, 2)
	bufI32[0] = make([]int32, 512)
	bufI32[1] = make([]int32, 512)
	fmt.Printf("  IsFormatSupported(2 channels, int32) err: %v\n", portaudio.IsFormatSupported(params, bufI32))

	bufI24 := make([][]portaudio.Int24, 1)
	bufI24[0] = make([]portaudio.Int24, 512)
	fmt.Printf("  IsFormatSupported(1 channel, portaudio.Int24) err: %v\n", portaudio.IsFormatSupported(params, bufI24))
	bufI24 = make([][]portaudio.Int24, 2)
	bufI24[0] = make([]portaudio.Int24, 512)
	bufI24[1] = make([]portaudio.Int24, 512)
	fmt.Printf("  IsFormatSupported(2 channels, portaudio.Int24) err: %v\n", portaudio.IsFormatSupported(params, bufI24))

	bufI16 := make([][]int16, 1)
	bufI16[0] = make([]int16, 512)
	fmt.Printf("  IsFormatSupported(1 channel, int16) err: %v\n", portaudio.IsFormatSupported(params, bufI16))
	bufI16 = make([][]int16, 2)
	bufI16[0] = make([]int16, 512)
	bufI16[1] = make([]int16, 512)
	fmt.Printf("  IsFormatSupported(2 channels, int16) err: %v\n", portaudio.IsFormatSupported(params, bufI16))

	bufI8 := make([][]int8, 1)
	bufI8[0] = make([]int8, 512)
	fmt.Printf("  IsFormatSupported(1 channel, int8) err: %v\n", portaudio.IsFormatSupported(params, bufI8))
	bufI8 = make([][]int8, 2)
	bufI8[0] = make([]int8, 512)
	bufI8[1] = make([]int8, 512)
	fmt.Printf("  IsFormatSupported(2 channels, int8) err: %v\n", portaudio.IsFormatSupported(params, bufI8))

	bufUI8 := make([][]uint8, 1)
	bufUI8[0] = make([]uint8, 512)
	fmt.Printf("  IsFormatSupported(1 channel, uint8) err: %v\n", portaudio.IsFormatSupported(params, bufUI8))
	bufUI8 = make([][]uint8, 2)
	bufUI8[0] = make([]uint8, 512)
	bufUI8[1] = make([]uint8, 512)
	fmt.Printf("  IsFormatSupported(2 channels, uint8) err: %v\n", portaudio.IsFormatSupported(params, bufUI8))
	fmt.Println()

	fmt.Println("Devices:")
	devices, err := portaudio.Devices()
	if err != nil {
		panic(err)
	}
	for _, device := range devices {
		printDevice(device)
	}
}

func printDevice(device *portaudio.DeviceInfo) {
	fmt.Printf("- Name: %s\n", device.Name)
	fmt.Printf("  DefaultSampleRate: %f\n", device.DefaultSampleRate)
	fmt.Printf("  MaxInputChannels: %d\n", device.MaxInputChannels)
	fmt.Println()
}

Hi, I'm running into the same issue when running the example code
./main.go:57:30: cannot use format (variable of type "github.com/faiface/beep".Format) as "github.com/gopxl/beep".Format value in argument to wav.Encode

I've fixed it but just using the faiface/beep/wav module but that doesn't seem like the ideal solution. This was also done in a completely clean environment with no modules installed before.

Please make sure you import github.com/gopxl/beep instead of github.com/faiface/beep everywhere including subpackages.

There's probably some broken dependency that still imports github.com/faiface/beep

Steps to reproduce my issue:
Start a fresh golang container. Copy paste the example code from this repo. Run go mod init and tidy

This is the go.mod after doing these steps


go 1.21.4

require (
        github.com/MarkKremer/microphone v1.1.0
        github.com/gopxl/beep v1.2.0
)

require (
        github.com/faiface/beep v1.0.2 // indirect
        github.com/gordonklaus/portaudio v0.0.0-20180817120803-00e7307ccd93 // indirect
        github.com/pkg/errors v0.9.1 // indirect
)```

I've created a release for the latest version of the microphone package (v1.2.0) and now Go should pick it up. If not, try to run go get github.com/MarkKremer/microphone@v1.2.0 and go mod tidy.

Sidenote: Github doesn't show the release on the releases page but it does exist. I'm not sure what's up with that.

Thank you for the reproduction steps!

Just tested it and works properly now. Thanks!

Thank you both for the feedback! I'm planning on using this very soon - will let you know how it goes :)