# How do I play sound in a notebook (preferably Pluto)?

**URL:** https://discourse.julialang.org/t/how-do-i-play-sound-in-a-notebook-preferably-pluto/49403
**Category:** General Usage
**Tags:** sound
**Created:** [November 1, 2020, 7:58am UTC](https://discourse.julialang.org/t/how-do-i-play-sound-in-a-notebook-preferably-pluto/49403 "2020-11-01T07:58:41Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![minetest2048](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/minetest2048/32/45961_2.png) [@minetest2048](https://discourse.julialang.org/u/minetest2048)
#### Post date: [November 1, 2020, 7:58am UTC](https://discourse.julialang.org/t/how-do-i-play-sound-in-a-notebook-preferably-pluto/49403/1 "2020-11-01T07:58:41Z")

</div>

I want to build a synthesizer in Julia, and I want to play the output inside the notebook, like this example for Jupyter+Python: [IPython Cookbook - 11.7. Creating a sound synthesizer in the Notebook](https://ipython-books.github.io/117-creating-a-sound-synthesizer-in-the-notebook/)  
I have searched how to play sound in Julia, and all of the libraries are either unmaintained (AudioIO.jl) or segfaults (PortAudio.jl)

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [November 1, 2020, 9:23am UTC](https://discourse.julialang.org/t/how-do-i-play-sound-in-a-notebook-preferably-pluto/49403/2 "2020-11-01T09:23:25Z")

</div>

There’s also JuliaMusic - eg things like [https://github.com/JuliaMusic/Mplay.jl](https://github.com/JuliaMusic/Mplay.jl) - as well as JuliaAudio. (The difference between music and audio is a question for another day… 😃)

---

<div class="post-metadata">

### Author: ![minetest2048](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/minetest2048/32/45961_2.png) [@minetest2048](https://discourse.julialang.org/u/minetest2048)
#### Post date: [November 7, 2020, 10:47am UTC](https://discourse.julialang.org/t/how-do-i-play-sound-in-a-notebook-preferably-pluto/49403/3 "2020-11-07T10:47:59Z")

</div>

The problem with Mplay is that its only a MIDI player, it doesn’t generate and play sounds by itself. And JuliaAudio doesn’t have any package that works with Julia 1.4.1 (JACKAudio.jl is deprecated, and PortAudio.jl does not officially support Julia 1.0 and above, and if I try to use it anyway, it segfaults).

And all of them plays the audio directly, it isn’t like Python notebooks where there is a play button in the notebook and the audio is playing through the browser

---

<div class="post-metadata">

### Author: ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)
#### Post date: [November 7, 2020, 11:53am UTC](https://discourse.julialang.org/t/how-do-i-play-sound-in-a-notebook-preferably-pluto/49403/4 "2020-11-07T11:53:19Z")

</div>

Yes, it’s not all there at present, unfortunately.

But I noticed [this](https://twitter.com/Mr_Auk/status/1324265811268276224) on Twitter, so something is possible…

---

<div class="post-metadata">

### Author: ![minetest2048](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/minetest2048/32/45961_2.png) [@minetest2048](https://discourse.julialang.org/u/minetest2048)
#### Post date: [November 10, 2020, 4:30am UTC](https://discourse.julialang.org/t/how-do-i-play-sound-in-a-notebook-preferably-pluto/49403/5 "2020-11-10T04:30:40Z")

</div>

The thing is that in that linked twitter thread, Julia controls Pure Data that actually generates and plays the sound, so again its not Julia that plays the sound, unlike Matlab play() and sound() functions.

To work around this I write the array into a file, then I run sox that reads from the file and plays the sound. Its a little bit round about, but it works perfectly both in REPL and Pluto

---

<div class="post-metadata">

### Author: ![fonsp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fonsp/32/222349_2.png) [@fonsp](https://discourse.julialang.org/u/fonsp)
#### Post date: [November 22, 2020, 12:44pm UTC](https://discourse.julialang.org/t/how-do-i-play-sound-in-a-notebook-preferably-pluto/49403/6 "2020-11-22T12:44:05Z")

</div>

If any of you find a Julia package that has basic types for waveforms and it does not play audio when you use it in Pluto, let me know! We can make this work pretty easily – I just need to add the audio MIME type.  
[fonsvdplas@gmail.com](mailto:fonsvdplas@gmail.com)

---

<div class="post-metadata">

### Author: ![mvsoom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mvsoom/32/31051_2.png) [@mvsoom](https://discourse.julialang.org/u/mvsoom)
#### Post date: [August 9, 2022, 3:58pm UTC](https://discourse.julialang.org/t/how-do-i-play-sound-in-a-notebook-preferably-pluto/49403/7 "2022-08-09T15:58:21Z")

</div>

This would be very nice, especially if it could be served online.

---

<div class="post-metadata">

### Author: ![thoughts4sounds](https://avatars.discourse-cdn.com/v4/letter/t/b19c9b/32.png) [@thoughts4sounds](https://discourse.julialang.org/u/thoughts4sounds)
#### Post date: [March 6, 2024, 3:59am UTC](https://discourse.julialang.org/t/how-do-i-play-sound-in-a-notebook-preferably-pluto/49403/8 "2024-03-06T03:59:34Z")

</div>

The easy way I found to do this was using PlutoUI

```julia
using WAV, PlutoUI

begin
	wavwrite(Int.(trunc.(y*2^15)), "audio.wav", Fs=sr, nbits=16)
	md"""$(LocalResource("audio.wav"))"""
end

```

somehow it doesn’t work if the raw Float data is written in `wavwrite`, so I needed to convert to Int16
