raudio
Version, currently 0.1.36 versions
github.com/kojix2/raudio.cr
No description declared in shard.yml.
Nothing has been indexed for 0.1.3 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
raudio:
github: kojix2/raudio.cr
version: ~> 0.1.3Then run:
shards installshard.yml
No shard.yml has been indexed for 0.1.3. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
raudio.cr
:sound: raudio - a simple audio library based on miniaudio - for Crystal
Installation
Add to shard.yml:
dependencies:
raudio:
github: kojix2/raudio.cr
Run shards install. The native library builds automatically.
Usage
Audio device
require "raudio"
Raudio::AudioDevice.open do
Raudio::AudioDevice.master_volume = 0.8
end
Sound playback
Raudio::AudioDevice.open do
sound = Raudio::Sound.load("effect.wav")
sound.volume = 0.5
sound.play
while sound.playing?
sleep 10.milliseconds
end
end
Music streaming
Raudio::AudioDevice.init
music = Raudio::Music.load("background.mp3")
music.volume = 0.8
music.looping = false # Disable looping (enabled by default)
music.play
loop do
music.update
break unless music.playing?
sleep 10.milliseconds
end
Raudio::AudioDevice.close
Wave data
Raudio::AudioDevice.open do
wave = Raudio::Wave.load("audio.wav")
sound = Raudio::Sound.from_wave(wave)
sound.play
wave.export("output.wav")
end
Resource Management
Resources should be explicitly released when done, or use the block form for automatic cleanup.
Recommended patterns:
# Block form (automatic cleanup)
Raudio::Sound.load("effect.wav") do |sound|
sound.play
end
# Manual release
sound = Raudio::Sound.load("effect.wav")
begin
sound.play
ensure
sound.release # or sound.close
end
Finalizers are provided as a fallback but explicit cleanup is recommended.
Playback model (practical)
- Non-blocking:
Sound#play/Music#playreturn immediately. Mixing/output is done on a separate audio thread (miniaudio). - Streaming: Call
Music#updateregularly (e.g. once per frame/tick) to refill the buffer and avoid underruns/stutter. - Threading:
AudioDevicelifetime operations are synchronized, and nested/concurrentAudioDevice.openblocks are reference-counted. IndividualSound,Music,Wave, andAudioStreamhandles should be owned from one audio/game context. - ExecutionContext: With
Fiber::ExecutionContext::Parallel, prefer sending audio commands through aChannelto a dedicated owner fiber orExecutionContext::Isolatedloop. This keeps resource release,Music#update, and playback state changes serialized without adding broad locks to every audio call. - Callbacks:
AudioStreamcallbacks/processors run from the audio backend thread. Keep them short and synchronize any shared application data yourself. - Device lifetime: After
AudioDevice.init, the device keeps running untilAudioDevice.close. WithAudioDevice.open, the device closes when the last active open block exits.
Supported formats
WAV, OGG, MP3, FLAC, QOA, XM, MOD
API
Raudio::AudioDevice- audio device managementRaudio::Sound- short audio clipsRaudio::Music- streaming audioRaudio::Wave- raw waveform dataRaudio::AudioStream- custom streaming
Low-level C bindings: Raudio::LibRaudio
Development
git clone --recursive https://github.com/kojix2/raudio.cr # submodule
make -C ext # build native library
crystal spec # run tests
crystal build examples/simple_sound.cr
./simple_sound # one of the two sounds will play
License
MIT
Dependencies (bundled single-header/native libraries):
- raudio (C library) – zlib
Summary: Project code is MIT, bundled raudio is zlib, and all other bundled dependencies are permissive (Public Domain, MIT-0, MIT, WTFPL v2) with no copyleft obligations.
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.3- Tagged
- Jun 23, 2026
- Commit
b4912bee1408- Indexed
- not yet
Dependents
Repository
github.com/kojix2/raudio.cr
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 13, 2026
- Synced
- Aug 13, 2026
- Versions
- 6