# Play a sound, any sound [closed]

Your program has to make the computer produce a sound, any sound.

Shortest code wins, not sooner than 10 days after the first valid answer. If there is a tie, the one submitted sooner, wins.

• The program should run on a reasonable, not too uncommon personal computer.
• Opening a pop-up, message box, etc. (for example, on a web page) does not count, as they might or might not produce a sound, depending on a lot of settings.
• Just entering a wrong command or invalid character on a console and receiving a warning beep does not count, just as the compiler/interpreter/OS beeping on an error or crash does not count either. Your code must be a valid program.
• ^G aka system bell or OS beep may be suppressed on many systems too (e.g. switched to be a visible "bell") and should be handled like sounds of popus and so on too: Not a valid solution.
– user19214
Jun 17, 2014 at 21:43
• Every program that prints "\a" to a terminal fails if xterm uses a visible bell. Jun 18, 2014 at 23:42
• rm / will cause a lot of screaming. Jun 22, 2014 at 17:23
• My left fan has been dying noisily for a while. Would that be a valid 0 bit answer? Sep 29, 2015 at 0:11
• I think this question should be reopened. The joke answers that rely on the fan spinning or the CD tray opening are invalid, since the question says "play a sound". Seems pretty clear to me that the output needs to come from the speakers as a result of the program, not the OS or the user or the hardware. Dec 2, 2016 at 19:40

## Bash, 26

Standard unix (not modern linux, sadly, unless you have alsa-oss installed; the BSDs are fine):

cat /dev/random > /dev/dsp

• You can save 2 bytes by removing the whitespace around >. Jun 8, 2014 at 21:34

# Scala: 44

java.awt.Toolkit.getDefaultToolkit().beep();


same as @nrubin29's answer, but shorter

# Linux shell (6 characters)

This requires a correctly configured analog modem (you also might need to run it as root):

wvdial


# GolfScript (3)

Since everyone else is doing this anyway:

'^G'


where ^G is the bell character.

Hex dump:

0000000: 2707 27                                  '.'

• Now what is it, '^G' or "^G"? Jun 15, 2014 at 15:34
• It doesn't matter, but I'll fix the inconsistency. Jun 15, 2014 at 15:34
• This is a duplicate of this answer. Jan 24, 2016 at 4:22

## sh 6

echo .


(where the . is in fact a BELL character)

The HEX representation of the above code is:

65 63 68 6f 20 07


Autoit 6

Beep()


Although declaring a function would allow for less characters, not counting the declaration:

z()
Func z()
Beep()
EndFunc

• That way that you made the program longer? It didn't make it shorter. May 4, 2013 at 17:45
• Writing own functions count toward the the length. otherwise everything would be a how can I call the method with less chars and some languages allow that with 1 char. May 10, 2013 at 0:15

# ATARI BASIC (4 chars)

?"E"


(? is short for "print". E is in fact the "escape" symbol; see http://raster.infos.cz/atari/chars/atascii.htm, item 1B. Printing this symbol would make a characteristic noise.)

### PowerShell, 3

'^G'


Of course, the ^G has to be entered manually, or written to a file with another script, like the following:

"'$([char]7)'"|Set-Content beep.ps1  ## VBScript CreateObject("SAPI.SpVoice").speak "a"  Nice thing about this is you can make it say anything you want. Matlab UNTESTED (1) ␇  I am not sure whether this works in matlab, as I don't have sound available, but ␇ is in fact a single character. Hence calling or printing it may produce the desired effect in some languages. Matlab verified (4) beep  • Calling the character actually does some strange things. See this question if you are interested. Jan 13, 2014 at 17:04 # Batch, 16 type sethc.exe  I discovered this. When I do this, I'll get the 'BEEP' sound from reading the < BELL > character. # Windows batch script, 14 sort %comspec%  %comspec% just points to C:\Windows\System32\cmd.exe, and calling sort will find the bell character at some point in cmd's binary. • Doesn't seem to work on Windows 8.1 64-bit. Jun 8, 2014 at 21:36 ## JS, 117 new Audio('data:audio/wav;base64,UklGRl9vT19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YU'+Array(1e3).join(123)).play()  • You can save 4 bytes by using audio instead of audio/wav, and 1 byte by using join(10) instead of join(123). Jun 8, 2014 at 21:21 • Even Array(10).join(1) appears to play a sound, but Array(99).join(9) is more audible. Jun 8, 2014 at 21:29 ## Java: 103 public class S { public static void main(String[] a) { java.awt.Toolkit.getDefaultToolkit().beep(); } }  • Will fail to compile without class wrapper and import. Jun 8, 2014 at 20:16 • I didn't realize we needed everything. I'll add it. Jun 8, 2014 at 21:00 # Python3 34 Any of the python versions printing the bell character to stdout was working for me, so here it is one using the standard libarary, in Windows: import winsound as w;w.Beep(99,99)  The semicolon could be replaced with a newline, but looks cooler this way :) • You can save a character by using from winsound import*;Beep(99,99). Jun 15, 2014 at 9:45 # JavaScript - 99 103 Audio ("data:audio;base64,UklGRgWsAABXQVZFZm10IBAAAAABAAEARKwAAESsAAABAAgAZGF0YeGrAACAbebe") .play();  *chirp* (in firefox, it is definitely a chirp) • This code throws the following error: TypeError: Failed to construct 'Audio': Please use the 'new' operator, this DOM object constructor cannot be called as a function. Jun 3, 2014 at 11:03 • firefox doesn't need that operator. however if i wanted to be pedantic (crossbrowser) i would definitely use 'new' (+4 characters) – bebe Jun 3, 2014 at 11:34 • I'm getting the error TypeError: Constructor Audio requires 'new' in Firefox Aurora 32. So yeah, it does. Jun 15, 2014 at 9:44 • oh dear.. "Omit the new keyword when possible" I had Firefox 29 now 30, it works like charm. (it's funny you try to prove your point with an alpha release) – bebe Jun 15, 2014 at 10:16 # QBASIC (8) PLAY "A"  Body must be at least 30 characters; you entered 19. ಠ_ಠ # Windows Command Promt logoff  Indeed, this makes an OS sound but it is not OS beeping on an error or crash. • Which version of DOS has a logoff command? Jun 15, 2014 at 15:29 • @celtschk I don't know why did I wrote that:D Jun 15, 2014 at 21:01 # Powershell, 4 "a"  Sends a beep signal to the computer's speaker. # Visual Basic 6 beep  VB 6, good times. ## C 23 Make a beep sound. int main(){putchar(7);}  • This should still compile without the int  at the beginning Jun 17, 2014 at 8:05 # Debianish solution, works on some other systems too - 9 chars aplay /i*  ...will play the files /initrd.img and initrd.img.old which are symlinks to some system startup ramdisks in directory /boot. If you prefer the sound of kernels, try... aplay /v*  ...and look yourself why it works or fails on your system. I got... $ LANG=C ls -l / | grep ^[^d]
total 88
lrwxrwxrwx   1 root root    36 Dec 15  2012 initrd.img -> /boot/initrd.img-3.2.0-0.bpo.4-amd64
lrwxrwxrwx   1 root root    30 Dec  9  2012 initrd.img.old -> boot/initrd.img-2.6.32-5-amd64
lrwxrwxrwx   1 root root     4 Dec  9  2012 lib64 -> /lib
lrwxrwxrwx   1 root root    32 Dec 15  2012 vmlinuz -> boot/vmlinuz-3.2.0-0.bpo.4-amd64
lrwxrwxrwx   1 root root    27 Dec  9  2012 vmlinuz.old -> boot/vmlinuz-2.6.32-5-amd64


...here and that may or may not explain a lot to you and I demand the absence of solid facts and that I may or may not be called vroomfondel!

• you are saying that your solution needs neccessary data - that may not even exist - from outside the code. i think it needs reasons to prove it's valid.
– bebe
Jun 17, 2014 at 22:08
• Oh... I didnt see my harddisk as "outside"! :-D ll think about a different solution for some minutes...
– user19214
Jun 17, 2014 at 22:18
• Ok... let's narrow it down: Debian is a common system and has these links... they can be disabled by editing some config file in /etc/ but their existence can be widely assumed because most users don't touch/change the defaults...
– user19214
Jun 17, 2014 at 22:30
• "The program should run on a reasonable, not too uncommon personal computer." was the wording I was looking for. And I think Debian not being configured to be far far away from the installation defaults on contemporary hardware does not describe an uncommon personal computer.
– user19214
Jun 17, 2014 at 22:42

# OS X Command Line

say a

This causes the computer to say the letter 'A'

• I do not think say is a bash command.
– user19214
Jun 17, 2014 at 21:24
• sorry, yeti. I was under the impression that OS X command line was Bash. Thank you for the correction Jun 18, 2014 at 6:03
• It may be BASH where you type say a but that does not make say a BASH command. So I meant something like "say is not part of the BASH language". Maybe that was trying to be too exact... it may have caused more confusion than needed...
– user19214
Jun 18, 2014 at 8:00

## PHP (CLI): 1 byte




Source code as seen in Notepad++:

In the absence of <?php opening tag, source code is simply dumped to output.

Yeah, I know, another BEL answer, but still, tough to beat a single byte, especially in an interpreted language like PHP ;)

# k/Q (6 chars)

Bell character to stdout.

1"c"$7  ## Windows Command Script - 1 Byte As most of the answers, this also uses the bell character. 0x07  Note: Must be run from console to work, since the sound needs some time to trigger. ## Spoon, 13 1111111001010  Similarly to the BF solution, it prints the bell character. # C++ 45 #include<iostream> int main(){std::cout<<'\a';}  # ZX Spectrum BASIC (3) SAVE STR$ PI


It is only 3 bytes because BASIC keywords (with surrounding spaces) occupy single byte in ZX spectrum's memory. Here's its hex representation:

F8 C1 A7


This program saves current program to audio tape under the name "3.1415927" which is the string representation of π.

In fact it require 7 keypresses: S Caps+Symbol Y Caps+Symbol M

## C#

System.Media.SystemSounds.Beep.Play();
`

It's long, but anyway...