https://github.com/binozo/gotinyalsa
Native Go bindings for TinyAlsa
https://github.com/binozo/gotinyalsa
alsa go tinyalsa
Last synced: 2 months ago
JSON representation
Native Go bindings for TinyAlsa
- Host: GitHub
- URL: https://github.com/binozo/gotinyalsa
- Owner: Binozo
- License: bsd-3-clause
- Created: 2023-11-04T20:57:04.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-08-23T13:51:57.000Z (9 months ago)
- Last Synced: 2024-08-23T15:26:50.160Z (9 months ago)
- Topics: alsa, go, tinyalsa
- Language: Go
- Homepage:
- Size: 45.9 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GoTinyAlsa 🚀
Go bindings for [TinyAlsa](https://github.com/tinyalsa/tinyalsa)
Features:
- ⚡ Easy yet powerful API
- 📱 Android support
- 🤓☝️ well documented## Installation
```
$ go get -u github.com/Binozo/GoTinyAlsa
```
## Troubleshooting
#### Linking
If you get the following error: `error while loading shared libraries: libtinyalsa.so.2: cannot open shared object file: No such file or directory`
and you built tinyalsa from source, make sure you set `LD_LIBRARY_PATH=/usr/local/lib` as an environment variable.#### Deprecation warnings
Those warnings
```shell
# github.com/Binozo/GoTinyAlsa/internal/tinyapi
cgo-gcc-prolog: In function ‘_cgo_ee639364c86c_Cfunc_pcm_read’:
cgo-gcc-prolog:152:2: warning: ‘pcm_read’ is deprecated [-Wdeprecated-declarations]
In file included from /usr/local/include/tinyalsa/asoundlib.h:33,
from ../internal/tinyapi/device.go:5:
```
are normal and to ensure compatibility with Android, we need to use those deprecated functions.
Take a look [here](https://github.com/tinyalsa/tinyalsa/blob/google-origin/include/tinyalsa/asoundlib.h) for available APIs for the Android platform.## Quickstart
> [!NOTE]
> Take a look at the `examples` folder for example usage.### Create your device
```go
package mainimport "github.com/Binozo/GoTinyAlsa"
func main() {
// You need to set deviceCard and deviceNr yourself
// To list output devices, execute 'aplay -L'
// To list input devices, execute 'arecord -L'
deviceCard := 4
deviceNr := 0
device := tinyalsa.NewDevice(deviceCard, deviceNr, pcm.Config{
Channels: 1,
SampleRate: 48000,
PeriodSize: 2048,
PeriodCount: 20,
Format: tinyalsa.PCM_FORMAT_S16_LE,
})
}
```### Wait until it's ready
```go
// Wait until our microphone (PCM_IN) input is ready with the maximum duration of 2 seconds
err := device.WaitUntilReady(tinyalsa.PCM_IN, time.Second*2)
if err != nil {
fmt.Println("An error occurred while waiting until device is ready:", err)
}
```