Play a wav file with Haskell

前端 未结 3 1439
时光说笑
时光说笑 2021-02-06 23:49

Is there a simple, direct way to play a WAV file from Haskell using some library and possibly such that I play many sounds at once?

I\'m aware of OpenAL but I\'m not wri

3条回答
  •  抹茶落季
    2021-02-07 00:45

    I realize this is not actually a convenient way to do it, but I had the test code lying around, so...

    {-# LANGUAGE NoImplicitPrelude #-}
    module Wav (main) where
    
    import Fay.W3C.Events
    import Fay.W3C.Html5
    
    import Language.Fay.FFI
    import Language.Fay.Prelude
    
    main :: Fay ()
    main = addWindowEventListener "load" run
    
    run :: Event -> Fay Bool
    run _ = do
        aud <- mkAudio
        setSrc aud "test.wav"
        play aud
        return False
    
    
    mkAudio :: Fay HTMLAudioElement
    mkAudio = ffi "new Audio()"
    
    addWindowEventListener :: String -> (Event -> Fay Bool) -> Fay ()
    addWindowEventListener = ffi "window['addEventListener'](%1,%2,false)"
    

    There you go--playing a WAV file in Haskell thanks to the power of HTML5! All you have to do is launch a web browser instead of mplayer. :D

提交回复
热议问题