Play a wav file with Haskell

前端 未结 3 1441
时光说笑
时光说笑 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:36

    using OpenAL through ALUT:

    import Control.Monad
    import Sound.ALUT
    
    playSound :: IO ()
    playSound =
      withProgNameAndArgs runALUTUsingCurrentContext $ \_ _ ->
      do
        (Just device) <- openDevice Nothing
        (Just context) <- createContext device []
        currentContext $= Just context
        buffer1 <- createBuffer $ Sine 440 0 1
        buffer2 <- createBuffer HelloWorld
        [source] <- genObjectNames 1
        queueBuffers source [buffer1,buffer2]
        play [source]
        sleep 4
        closeDevice device
        return ()
    
    main = playSound
    

    to load a wav file:

    buffer3 <- createBuffer $ File "/path/to/file.wav"
    

    credit goes to Chris Double: http://bluishcoder.co.nz/articles/haskell/openal.html

提交回复
热议问题