Documentation
¶
Overview ¶
Package microphone provides a wrapper around the PortAudio microphone stream to make it compatible with the beep audio library.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Init ¶
func Init() error
Init initializes internal datastructures of PortAudio and the host APIs for use.
This method exists as a convenient single point of contact if the client doesn't use any other PortAudio functionality. Otherwise, calling portaudio.Initialize() is recommended instead of calling this method.
func Terminate ¶
func Terminate() error
Terminate deallocates all resources allocated by PortAudio.
This method exists as a convenient single point of contact if the client doesn't use any other PortAudio functionality. Otherwise, calling portaudio.Terminate() is recommended instead of calling this method.
Terminate MUST be called before exiting a program which uses PortAudio. Failure to do so may result in serious resource leaks, such as audio devices not being available until the next reboot.
Types ¶
type Streamer ¶
type Streamer struct {
// contains filtered or unexported fields
}
Streamer is an implementation of the beep.StreamCloser interface to provide access to the microphone through the PulseAudio library.
func OpenDefaultStream ¶
func OpenDefaultStream(sampleRate beep.SampleRate, inputChannels int) (s *Streamer, format beep.Format, err error)
OpenDefaultStream opens the default input stream.
Example (RecordWav) ¶
if len(os.Args) < 2 { fmt.Println("missing required argument: output file name") return } fmt.Println("Recording. Press Ctrl-C to stop.") err := Init() if err != nil { log.Fatal(err) } defer Terminate() stream, format, err := OpenDefaultStream(44100, 1) if err != nil { log.Fatal(err) } // Close the stream at the end if it hasn't already been // closed explicitly. defer stream.Close() filename := os.Args[1] if !strings.HasSuffix(filename, ".wav") { filename += ".wav" } f, err := os.Create(filename) if err != nil { log.Fatal(err) } // Stop the stream when the user tries to quit the program. sig := make(chan os.Signal, 1) signal.Notify(sig, os.Interrupt, os.Kill) go func() { <-sig stream.Stop() stream.Close() }() stream.Start() // Encode the stream. This is a blocking operation because // wav.Encode will try to drain the stream. However, this // doesn't happen until stream.Close() is called. err = wav.Encode(f, stream, format) if err != nil { log.Fatal(err) }
Output:
func (*Streamer) Err ¶
Err returns an error that occurred during streaming. If no error occurred, nil is returned.