terremoth/php-win32-playwav

Play wav (wave) files natively with PHP on Windows

v1.0.0 2024-11-20 12:25 UTC

This package is auto-updated.

Last update: 2025-03-20 13:13:49 UTC


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 ⚡ & ❤

CodeCov Psalm type coverage Psalm level Test Run Status Test Coverage Codacy Badge Maintainability License

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();