(ql:quickload '(cl-out123 cl-mpg123)) (defun play-mp3 (file &key driver output (buffer-size T)) (let* ((file (cl-mpg123:connect (cl-mpg123:make-file file :buffer-size buffer-size))) (out (cl-out123:connect (cl-out123:make-output driver :device output)))) (format T "Playback device ~a / ~a" (cl-out123:driver out) (cl-out123:device out)) (multiple-value-bind (rate channels encoding) (cl-mpg123:file-format file) (format T "Input format ~a Hz, ~a channels, ~a encoded." rate channels encoding) (cl-out123:start out :rate rate :channels channels :encoding encoding)) (unwind-protect (loop with buffer = (cl-mpg123:buffer file) for read = (cl-mpg123:process file) for played = (cl-out123:play out buffer read) while (< 0 read) do (when (/= played read) (format T "Playback is not catching up with input by ~a bytes." (- read played)))) (cl-out123:stop out) (cl-out123:disconnect out) (cl-mpg123:disconnect file))))