terremoth / php-win32-playwav
Play wav (wave) files natively with PHP on Windows
v1.0.0
2024-11-20 12:25 UTC
Requires
- php: ^8.1
- ext-ffi: *
Requires (Dev)
- nikic/php-parser: ^4.10
- phpmd/phpmd: @stable
- phpunit/phpunit: ^10.0
- squizlabs/php_codesniffer: *
- vimeo/psalm: ^5.0
README
Play wav (wave) files natively with PHP on Windows. Zero extensions or dependencies needed!
It uses PlaySound
from winmm.dll
, unlocked by the power of PHP FFI
Not because we must do it, but because we can!
Made by Terremoth with ⚡ & ❤
See demos/demo.php for examples.
Installation
composer require terremoth/php-win32-playwav
Documentation
Play Sync
<?php require 'vendor/autoload.php'; use Win32Sound\PlayWav; $sound = new PlayWav('test.wav'); $sound->play();
Play Async
<?php require 'vendor/autoload.php'; use Win32Sound\PlayWav; $sound = new PlayWav('test.wav'); $sound->async()->play();
Loop the audio
Also, you can "loop" and then, stop if you want.
IMPORTANT: loop()
requires ->async()
at some point, in order to work due to Windows API:
<?php require 'vendor/autoload.php'; use Win32Sound\PlayWav; $sound = new PlayWav('test.wav'); $sound->async()->loop()->play(); // if the scripts ends it will "kill" the audio process, // so, to listen just put a sleep in order to test sleep(5); // if you want to stop the looping audio, just: $sound->stop();