Play a sound, any sound

43

12

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.

vsz

Posted 2012-11-17T18:06:35.530

Reputation: 7 963

Question was closed 2016-12-02T20:44:02.103

My left fan has been dying noisily for a while. Would that be a valid 0 bit answer? – Édouard – 2015-09-29T00:11:43.353

1I 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. – mbomb007 – 2016-12-02T19:40:58.193

1^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. – None – 2014-06-17T21:43:42.440

Every program that prints "\a" to a terminal fails if xterm uses a visible bell. – kernigh – 2014-06-18T23:42:16.970

19rm / will cause a lot of screaming. – cjfaure – 2014-06-22T17:23:26.037

Answers

20

dc, 2 chars

this one prints the bell character, too:

7P

Run with $ dc <<< 7P or save 7P to file and run $ dc file.

Also:

Befunge, 2 chars

Similar but infinitly looping and beeping:

7,

daniero

Posted 2012-11-17T18:06:35.530

Reputation: 17 193

1Could you please elaborate what language that is? I never heard about it, and its name is too short (and a very common abbreviation) to be efficiently searched for. – vsz – 2012-11-24T17:35:48.003

3From the man-page: dc is a reverse-polish desk calculator which supports unlimited precision arithmetic. -- it's included in most linux/unix distros as far as I know. – daniero – 2012-11-24T20:12:25.957

A few more examples if you're interested: 1, 2 and 3. Seen a few others use it here as well.

– daniero – 2012-11-24T20:20:53.273

My bad for not elaborating what I mean under "language" – vsz – 2012-11-30T11:40:05.797

9@vsz dc is – of course – turing complete, as any better calculator such as ghc should be. – FUZxxl – 2012-12-03T21:54:42.273

Here no ^G produces a sound... ^G should not count as valid answer because it can be disabled like window-create and other OS sounds... – None – 2014-06-17T21:23:51.033

4All sounds can be disabled. Just turn the volume down. – daviewales – 2014-06-18T08:53:50.590

49

bash (13)

sudo rm -rf /

The faster the hard drive the better the sound. Don't work with SSDs.
(Don't try this at home, sudo rm -rf / erases everything on your hard drive)

Daniel

Posted 2012-11-17T18:06:35.530

Reputation: 1 801

1The warning Don't try this at home.. is misleading - someone might try this e.g. in /tmp/ instead of ~/, which would be equally harmful (: – mykhal – 2015-07-08T10:07:30.077

7I think that one should come with a disclaimer -- "Don't try this at home" :D – daniero – 2012-11-24T20:28:52.947

22Yeah, that's the sound when your computer reads your mail really fast (rm -rf). – FUZxxl – 2012-12-03T22:27:22.337

70Wait, you got it wrong. The task is to make the computer produce a sound, not the user... though I have to admit that scream was quite impressive... – ceased to turn counterclockwis – 2012-12-03T22:51:11.543

1Don't try this at home so it's OK at work... – tigrou – 2016-11-17T14:56:34.250

4It doesn't do anything without --no-preserve-root, except maybe on ancient systems. – nyuszika7h – 2014-06-09T14:58:16.523

1@nyuszika7h ancient as in before 2005. – Jwosty – 2014-06-16T22:21:30.210

44

*sh (5)

eject

(does not work if you have no CD/DVD or similar drive..)

mykhal

Posted 2012-11-17T18:06:35.530

Reputation: 641

I like this one. But, on my Mac (Mac OS X), the command is not found : sh: eject: command not found – Nicolas Barbulesco – 2014-06-07T20:27:40.580

3

Nicolas: right, on Mac, the eject "command" seems to be much shorter: (:

– mykhal – 2014-06-10T07:59:46.880

@ mykhal — If you go this way, I have a solution that works on all modern Macs : http://www.woowoomac.com/storage/post-images/adjust-volume-mac-keyboard.png?__SQUARESPACE_CACHEVERSION=1286394681886

– Nicolas Barbulesco – 2014-06-11T21:44:13.357

1This fails with OpenBSD. usage: eject [-t] device The device argument is not optional! The shortest that works here is eject cd0 for 9 characters. Also, if the drive has no tray (as with a slot-loading drive), then eject cd0 makes no noise unless a disc is in the drive. – kernigh – 2014-06-18T23:32:24.330

1kernigh: you're right. on the other hand, it might succeed on many systems without a sound card or speaker, where most of the other solutions would fail – mykhal – 2014-06-19T14:36:11.140

37

Befunge, 0

If I read the spec correctly, this is an endless loop.
Endless loop = you'll hear your CPU cooler spin up.

Johannes Kuhn

Posted 2012-11-17T18:06:35.530

Reputation: 7 122

27

sh 7

w|aplay

Plays a short noise.

Also 7:

aplay *

Assembly

Another non-bell solution. Resulting binary is just 15 bytes.

mov al, 182
out 43h, al
out 42h, al
mov al, 16
out 42h, al
mov al, 3
out 61h, al
ret

Assemble with nasm sound.asm -o sound.com. Can be tried with dosbox sound.com.

copy

Posted 2012-11-17T18:06:35.530

Reputation: 6 466

9+1 for not just relying on a terminal to translate BEL characters to beeps. – Ilmari Karonen – 2012-11-18T12:28:38.507

25

brainfuck: 8

+++++++.

Prints the bell character.

cardboard_box

Posted 2012-11-17T18:06:35.530

Reputation: 5 150

16+1 BF Solution both understandable AND shorter than C. – OldCurmudgeon – 2012-11-18T00:27:20.993

15A brainfuck is easier to mentally digest than C... we should learn from this incident. – Camilo Martin – 2012-12-18T14:10:31.100

23

bash (Mac OS X) 5

say a

although stylistically I prefer the somewhat longer:

say 'Hello, Code Golf !'

Paul R

Posted 2012-11-17T18:06:35.530

Reputation: 2 893

1If your Mac is set to English, you could also do say 'hahahahahahahahahahahahahahahahahahahahahahahahahaj'. – tomsmeding – 2012-12-29T14:23:53.370

21Oooh... I've got ssh access to an osx box... – boothby – 2013-05-04T17:43:13.970

1This command works in AppleScript. I did not know it works in the Terminal too. Funny with ssh ! – Nicolas Barbulesco – 2014-06-07T20:30:45.053

1Corollary on Linux: espeak... – daviewales – 2014-06-18T08:57:51.927

19

Haha, good ol' QBASIC code.

BEEP

Soham Chowdhury

Posted 2012-11-17T18:06:35.530

Reputation: 1 449

1

Ah, the fun that could be had with the PLAY command! For reminiscence, see e.g. this video.

– Jussi M – 2014-03-12T19:19:51.487

1I'm 15, xD. We learned QBASIC in school. – Soham Chowdhury – 2014-03-14T08:29:06.473

16

Python 3.3.3, one character

<bell character>

The error message will contain a bell character, causing the sound.

Python 3.3.3, 10 characters

If errors are not allowed, this solution won't output the error message, only the sound.

print('<bell character>')

user12487

Posted 2012-11-17T18:06:35.530

Reputation:

Why the downvote, this code actually produces a sound. – None – 2014-01-01T18:14:22.647

11 char O_o nice +1 – Timtech – 2014-01-02T01:38:00.717

13

Golfscript 3

'.'

(where the . is in fact a BELL character)

The HEX representation of the above code is:

27 07 27

Cristian Lupascu

Posted 2012-11-17T18:06:35.530

Reputation: 8 369

2Ouch, Golfscript strikes again! – vsz – 2012-11-17T18:27:46.447

12

Java - 222

Enough of this bell character or predefined beep function stuff, this makes a real sound :)

import javax.sound.sampled.*;class S{static{try{SourceDataLine
l=AudioSystem.getSourceDataLine(new
AudioFormat(4000,8,1,0<1,0>1));l.open();l.start();for(byte
i=9;i!=0;i+=9)l.write(new byte[]{i},0,1);}catch(Exception e){}}}

aditsu quit because SE is EVIL

Posted 2012-11-17T18:06:35.530

Reputation: 22 326

18Java truly sucks for golf – boothby – 2013-05-04T17:44:00.130

1

@boothby not always, check this out

– aditsu quit because SE is EVIL – 2013-05-06T01:07:22.937

20Okay, Java sucks for golf except when the challenge is to throw errors. ;) – boothby – 2013-05-06T01:47:22.573

@boothby What about this? http://codegolf.stackexchange.com/a/28818/24965

– stommestack – 2014-06-11T14:25:45.207

2@JopVernooij That's not golf, that's an underhanded popularity contest. – Jwosty – 2014-06-16T22:26:00.080

10

DOS Prompt / DOS Script

a:

Requires 3.5" floppy drive :)

svidgen

Posted 2012-11-17T18:06:35.530

Reputation: 311

What magic is this? – seequ – 2014-06-08T21:44:10.500

1It causes DOS to try to read from the floppy, which does cause a sound. It is, however, wrong that this needs a 3.5" floppy drive; a 5.25" floppy drive works even better. – celtschk – 2014-06-15T14:02:32.437

Aye. Wouldn't the 5.25" normally be b:? – svidgen – 2014-06-15T15:26:35.657

1Try a CD drive with a defective disk inside, works great too :) – Alejandro – 2014-06-15T17:53:33.450

The drive letter in DOS depended on which connectors of the cable the drive was attached to (and on newer machines, a BIOS setting). My first computer only had a 5.25" drive and I had to attach it as master (making it the A drive), since it couldn't boot from the slave. – Dennis – 2014-10-02T21:47:22.357

9

Pascal: 30 characters

uses Crt;begin
Sound(999)
end.

This takes advantage of the lack of any rule regarding the sound's duration. So just turns on the speaker on 999 Hz and lets it so. (At least until another program calls Nosound or the computer is turned off.)

manatwork

Posted 2012-11-17T18:06:35.530

Reputation: 17 865

-2: Change to 9 Hz: Sound(9). – Erik the Outgolfer – 2016-07-19T11:54:15.293

@EʀɪᴋᴛʜᴇGᴏʟғᴇʀ, would be hard to prove the sound is actually generated. Frequency Range of Human Hearing

– manatwork – 2016-07-19T12:05:34.310

@manatwork Well, add an identical code with another frequency that can be heard. Because the codes are identical, it can be proved. (the number only changes) – Erik the Outgolfer – 2016-07-19T12:08:01.557

And the sound keeps screaming even after the program has quit ? I like this one ! :-) – Nicolas Barbulesco – 2014-06-22T16:35:31.287

@NicolasBarbulesco, exactly. That was the normal behaviour of all programs on DOS, including those written in C or assembly. – manatwork – 2014-06-23T09:46:14.623

9

J (2)

a.

This prints all the characters from 0 to 255, that includes the bell.

If I have to do it without printing anything else, it's 4 characters:

7{a.

marinus

Posted 2012-11-17T18:06:35.530

Reputation: 30 224

8

Bash, 22

Back in the 90's, my brother taught me this one -- to be used in a computer lab where one has remote access and knows a person to be alone in said lab. Kids these days won't know what a computer lab is... but oh well.

cd /dev;cat sda1>audio

boothby

Posted 2012-11-17T18:06:35.530

Reputation: 9 038

cat /dev/sda1>audio – Erik the Outgolfer – 2016-07-19T12:35:14.920

1I get bash: audio: Permission denied even running under sudo. :( – Riking – 2013-05-05T04:46:43.947

2This worked on Debian as of 2006. I can't get it to work on my Ubuntu box :*( – boothby – 2013-05-05T15:41:13.027

1I think you mean dsp, not audio. See below for a similar example I wrote using /dev/random – None – 2014-01-02T01:42:55.067

3or cat /dev/sda | aplay – TheDoctor – 2014-03-04T00:23:21.977

1@TheDoctor or aplay</dev/sda (UUOC ;-)) – Digital Trauma – 2014-06-12T17:06:43.760

What is this supposed to do ? – Nicolas Barbulesco – 2014-06-22T16:04:14.293

8

Mathematica 6

This will evoke the system beep. On my computer, it is currently a chirp.

Beep[]

DavidC

Posted 2012-11-17T18:06:35.530

Reputation: 24 524

7

cat/type/PHP 1

This is actually polyglot. It runs in cat (or Microsoft Cat called type) and PHP.

$ xxd file
0000000: 07                                       .

Execution:

$ xxd -r > file
0000000: 07                                       .
^D
$ cat file # cat could be replaced with type (on Windows) or with php

Konrad Borowski

Posted 2012-11-17T18:06:35.530

Reputation: 11 185

That's not a serious attempt. – user48538 – 2016-03-03T11:10:45.273

What is the program ? How to run it ? This is not clear. – Nicolas Barbulesco – 2014-06-07T20:36:24.637

@NicolasBarbulesco: The program is one byte (\x07), however because it's binary, I cannot paste it here. You can run it in PHP CLI, with php. – Konrad Borowski – 2014-06-08T07:01:07.303

It is not clear. But it works ! With cat. The trick is the ASCII char 7 “bell”. – Nicolas Barbulesco – 2014-06-08T15:48:06.373

6

brainfuck, 5 bytes

+[.+]

prints all chars including bell

benwaffle

Posted 2012-11-17T18:06:35.530

Reputation: 199

5

Ruby, 7

$><<?\a

Tested on Windows with Ruby 1.9.3.

Roy Tinker

Posted 2012-11-17T18:06:35.530

Reputation: 146

5

DOS, 5

Indirect, requires user cooperation.

pause

boothby

Posted 2012-11-17T18:06:35.530

Reputation: 9 038

1Are you sure? I can not remember any beeping version of DOS pause. (At least not MSDOS and FreeDOS.) – manatwork – 2013-05-04T09:42:19.303

6Run the program. Cooperate. Listen. – boothby – 2013-05-04T17:36:10.367

1Could you at least specify which DOS implementation's which version you used? – manatwork – 2013-05-04T17:38:17.697

1Looked up. Found no mention of pause making sound. Tried it. pause made no sound. – manatwork – 2013-05-04T18:10:50.527

2You have to press a key... which makes a sound. @mana He said it was indirect - pause didn't make the sound, YOU did. – Riking – 2013-05-05T04:48:33.863

2@Riking, how that conforms with the “Your program has to make the computer produce a sound” part of the requirement? – manatwork – 2013-05-05T09:52:10.473

5I do not understand programmers on puzzle sites who cannot think outside of the box. – boothby – 2013-05-05T18:20:35.303

Well, "playing a sound" cannot be considered as a "puzzle", anyway. Just move on. Nobody can feel "puzzled" by that. – None – 2013-05-06T01:35:40.387

@JoanLeaven Who said this was a puzzle? I said this was a puzzle site -- do you read (I like reading)? Well, except for manatwork, who was obviously puzzled by my far-too-subtle joke. And anyway, you move on! This is my solution, I'll comment as often as I please! – boothby – 2013-05-06T01:45:29.973

4I wasn't criticizing your answer. I was criticizing the question. A pointless question will obviously get pointless answers. Your answer then make as much sense as any other answer to that stupid question. So, i'm giving you +1. – None – 2013-05-06T02:00:59.057

5

PowerShell, 24 17

Since nobody has posted this version yet:

[console]::beep()

UPDATE: Removed frequencies so it uses the default frequency and duration (MSDN says the default is 800 hertz and 200 milliseconds)

ub3rst4r

Posted 2012-11-17T18:06:35.530

Reputation: 282

Surely you could at least use smaller numbers – Dennis Jaheruddin – 2014-01-13T17:06:51.280

5

R 9

The bell character

cat("\a")

Dason

Posted 2012-11-17T18:06:35.530

Reputation: 260

4

Python 9 chars


produces beep sound when executed.

print'\a'

Anbarasan

Posted 2012-11-17T18:06:35.530

Reputation: 79

1You can shorten this to 8 characters if you replace \a with the actual bell character (ASCII code 7). – flornquake – 2013-05-03T16:37:26.887

But how to print with the help of the value 7 ? – Anbarasan – 2013-05-06T03:55:26.353

1

You can type the bell character into your editor with Alt+07. Alternatively, you can run this snippet to create a python file with the 8-character solution: open("play_a_sound.py", 'w').write("print'"+chr(7)+"'")

– flornquake – 2013-05-06T11:33:46.720

Got it now. Thanks ! – Anbarasan – 2013-05-07T03:55:37.103

4

Applescript (4 Characters)

beep

This will play the default beep sound of OS X.

Mathias

Posted 2012-11-17T18:06:35.530

Reputation: 41

4

top & aplay - 9

top has rhythm!

top|aplay

The periodic display sometimes does not feed the sound sink fast enough but aplay continues after grouching a bit... :-)

...this will run on many Linuxes...

Bonus:

While running this, type "s 1 ENTER" to get more beats per second. :-)

Party on!!! \o/

user19214

Posted 2012-11-17T18:06:35.530

Reputation:

This is pure genius... :D – Mega Man – 2016-08-01T08:26:36.953

4

Mathematica 7

Using Mathematica's built in text to speech capability.

Speak@x

Will make it say "x"

Tally

Posted 2012-11-17T18:06:35.530

Reputation: 387

3

Tcl, 1 char

-

replace - with the bell char.
It will print the bell char as part of the error message. Twice.

And if you think this is not a valid program, add this before the bell char:

proc \007 {} {};

It is a valid program, I just did not define the command, because I like the error message.

Johannes Kuhn

Posted 2012-11-17T18:06:35.530

Reputation: 7 122

Is that based on some Tcl 8.6 feature? In Tcl 8.5 I got different result: http://pastebin.com/bh73UF6F Or are you on Windows?

– manatwork – 2013-05-03T15:19:44.043

No. The 2nd part should show that this is a valid Tcl file. And it should beep 2x (the error message contains the command to be executed twice). Calling a command that does not exist is not an error for Tcl, it is only one if it can not find it. (e.g. parray, which is loaded on the first use) – Johannes Kuhn – 2013-05-03T16:28:43.087

Oops. I misunderstood you. I thought you mean, it should beep with the proc declaration too. (Regarding the beep count, probably my terminal is doing something as puts [string repeat ".\a" 10] displays 10 dots but beeps only once.) – manatwork – 2013-05-03T16:37:44.837

3

C: 19

main(){puts("\a");}

edit: header file is not needed for "puts"

Trevor Hickey

Posted 2012-11-17T18:06:35.530

Reputation: 341

2You can remove the space between #include and < :) – tomsmeding – 2012-11-18T08:13:33.847

puts(char*);main(){puts("\a");} is smaller IMHO. – FUZxxl – 2012-12-03T22:26:27.140

You can just remove the #include. – ugoren – 2012-12-04T08:10:39.363

1@FUZxxl How can you have an opinion about code size? – Doorknob – 2013-12-22T00:24:29.363

@DoorknobofSnow Because of the first amendment? – FUZxxl – 2013-12-22T00:35:29.543

The First Amendment of what country, again? Oh wait, this is the Internet and not a specific country. – DeadMG – 2014-01-01T15:16:24.510

3

><> 3

As in all answers, prints the bell (0x07) to stdout.

7o;

tomsmeding

Posted 2012-11-17T18:06:35.530

Reputation: 2 034

2

Bash, 26

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

cat /dev/random > /dev/dsp

user12447

Posted 2012-11-17T18:06:35.530

Reputation:

4You can save 2 bytes by removing the whitespace around >. – nyuszika7h – 2014-06-08T21:34:34.423

2

Scala: 44

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

same as @nrubin29's answer, but shorter

Avinash R

Posted 2012-11-17T18:06:35.530

Reputation: 181

2

GolfScript (3)

Since everyone else is doing this anyway:

'^G'

where ^G is the bell character.

Hex dump:

0000000: 2707 27                                  '.'

nyuszika7h

Posted 2012-11-17T18:06:35.530

Reputation: 1 624

This is a duplicate of this answer.

– Dennis – 2016-01-24T04:22:47.793

Now what is it, '^G' or "^G"? – celtschk – 2014-06-15T15:34:16.347

It doesn't matter, but I'll fix the inconsistency. – nyuszika7h – 2014-06-15T15:34:54.450

2

Linux shell (6 characters)

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

wvdial

celtschk

Posted 2012-11-17T18:06:35.530

Reputation: 4 650

2

Ruby 8

 puts"\a"

Tested on Windows with Ruby 1.9.3.

Cristian Lupascu

Posted 2012-11-17T18:06:35.530

Reputation: 8 369

1

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.)

Kaz Dragon

Posted 2012-11-17T18:06:35.530

Reputation: 149

1

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

Joey

Posted 2012-11-17T18:06:35.530

Reputation: 12 260

1

VBScript

CreateObject("SAPI.SpVoice").speak "a"

Nice thing about this is you can make it say anything you want.

Cheezey

Posted 2012-11-17T18:06:35.530

Reputation: 111

1

Windows Command Promt

logoff

Indeed, this makes an OS sound but it is not OS beeping on an error or crash.

totymedli

Posted 2012-11-17T18:06:35.530

Reputation: 361

Which version of DOS has a logoff command? – celtschk – 2014-06-15T15:29:24.550

@celtschk I don't know why did I wrote that:D – totymedli – 2014-06-15T21:01:13.810

1

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

Dennis Jaheruddin

Posted 2012-11-17T18:06:35.530

Reputation: 1 848

Calling the character actually does some strange things. See this question if you are interested.

– Dennis Jaheruddin – 2014-01-13T17:04:16.410

1

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.

afuous

Posted 2012-11-17T18:06:35.530

Reputation: 429

Doesn't seem to work on Windows 8.1 64-bit. – nyuszika7h – 2014-06-08T21:36:18.700

1

Batch, 16

type sethc.exe

I discovered this. When I do this, I'll get the 'BEEP' sound from reading the < BELL > character.

Gavriel Feria

Posted 2012-11-17T18:06:35.530

Reputation: 133

1

JavaScript - 99 103

Audio
  ("data:audio;base64,UklGRgWsAABXQVZFZm10IBAAAAABAAEARKwAAESsAAABAAgAZGF0YeGrAACAbebe")
.play();

*chirp* (in firefox, it is definitely a chirp)

bebe

Posted 2012-11-17T18:06:35.530

Reputation: 3 916

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. – starbeamrainbowlabs – 2014-06-03T11:03:00.483

firefox doesn't need that operator. however if i wanted to be pedantic (crossbrowser) i would definitely use 'new' (+4 characters) – bebe – 2014-06-03T11:34:04.237

I'm getting the error TypeError: Constructor Audio requires 'new' in Firefox Aurora 32. So yeah, it does. – nyuszika7h – 2014-06-15T09:44:01.143

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 – 2014-06-15T10:16:15.230

1

Java: 103

public class S {
    public static void main(String[] a) {
        java.awt.Toolkit.getDefaultToolkit().beep();
    }
}

nrubin29

Posted 2012-11-17T18:06:35.530

Reputation: 225

Will fail to compile without class wrapper and import. – Avinash R – 2014-06-08T20:16:40.647

I didn't realize we needed everything. I'll add it. – nrubin29 – 2014-06-08T21:00:47.210

1

JS, 117

new Audio('data:audio/wav;base64,UklGRl9vT19XQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YU'+Array(1e3).join(123)).play()

xem

Posted 2012-11-17T18:06:35.530

Reputation: 5 523

1You can save 4 bytes by using audio instead of audio/wav, and 1 byte by using join(10) instead of join(123). – nyuszika7h – 2014-06-08T21:21:52.903

Even Array(10).join(1) appears to play a sound, but Array(99).join(9) is more audible. – nyuszika7h – 2014-06-08T21:29:21.187

1

QBASIC (8)

PLAY "A"

Body must be at least 30 characters; you entered 19.

ಠ_ಠ

nyuszika7h

Posted 2012-11-17T18:06:35.530

Reputation: 1 624

1

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 :)

gcq

Posted 2012-11-17T18:06:35.530

Reputation: 251

2You can save a character by using from winsound import*;Beep(99,99). – nyuszika7h – 2014-06-15T09:45:51.170

1

Powershell, 4

"`a"

Sends a beep signal to the computer's speaker.

DarkAjax

Posted 2012-11-17T18:06:35.530

Reputation: 669

1

OS X Command Line

say a

This causes the computer to say the letter 'A'

Trent

Posted 2012-11-17T18:06:35.530

Reputation: 111

I do not think say is a bash command. – None – 2014-06-17T21:24:59.693

sorry, yeti. I was under the impression that OS X command line was Bash. Thank you for the correction – Trent – 2014-06-18T06:03:21.977

2It 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... – None – 2014-06-18T08:00:34.483

1

Visual Basic 6

beep

VB 6, good times.

Evgheni Crujcov

Posted 2012-11-17T18:06:35.530

Reputation: 111

1

C 23

Make a beep sound.

int main(){putchar(7);}

bacchusbeale

Posted 2012-11-17T18:06:35.530

Reputation: 1 235

3This should still compile without the int at the beginning – r3mainer – 2014-06-17T08:05:49.273

1

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!

user19214

Posted 2012-11-17T18:06:35.530

Reputation:

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 – 2014-06-17T22:08:38.110

Oh... I didnt see my harddisk as "outside"! :-D               ll think about a different solution for some minutes... – None – 2014-06-17T22:18:04.893

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... – None – 2014-06-17T22:30:53.263

1"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. – None – 2014-06-17T22:42:07.140

1

PHP (CLI): 1 byte

 

Source code as seen in Notepad++:

source code

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 ;)

Niet the Dark Absol

Posted 2012-11-17T18:06:35.530

Reputation: 647

1

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

Jonathan Callen

Posted 2012-11-17T18:06:35.530

Reputation: 111

1

Autoit 6

Beep()

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

z()
Func z()
Beep()
EndFunc

Giulio Muscarello

Posted 2012-11-17T18:06:35.530

Reputation: 298

5That way that you made the program longer? It didn't make it shorter. – boothby – 2013-05-04T17:45:35.587

1Writing 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. – Johannes Kuhn – 2013-05-10T00:15:54.097

0

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.

Robert Sørlie

Posted 2012-11-17T18:06:35.530

Reputation: 1 036

0

Spoon, 13

1111111001010

Similarly to the BF solution, it prints the bell character.

Timtech

Posted 2012-11-17T18:06:35.530

Reputation: 12 038

0

C++ 45

#include<iostream>
int main(){std::cout<<'\a';}

Mukul Kumar

Posted 2012-11-17T18:06:35.530

Reputation: 2 585

0

Fortran 95, 18 chars

print*,char(7);end

Produces a bell sound

gilbertohasnofb

Posted 2012-11-17T18:06:35.530

Reputation: 494

0

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

Vovanium

Posted 2012-11-17T18:06:35.530

Reputation: 286

0

C#

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

It's long, but anyway...

Tr00rle

Posted 2012-11-17T18:06:35.530

Reputation: 311

0

R, 7

alert()

but sadly I think this is just a wrapper for printing the bell character.

user25359

Posted 2012-11-17T18:06:35.530

Reputation: 1

0

In AppleScript ; 4 characters

beep

[ This is so short that my answer firstly did not reach the minimum length to be posted ! ]

Nicolas Barbulesco

Posted 2012-11-17T18:06:35.530

Reputation: 249

0

Ruby, 8 chars

puts ?\a

><>, 2-3 chars

7o;

or with infinite loop:

7o

clap

Posted 2012-11-17T18:06:35.530

Reputation: 834

0

Autohotkey

I found my answer in the Documentation on the Autohotkey Docs.

SoundBeep

XiKuuKy

Posted 2012-11-17T18:06:35.530

Reputation: 369

0

C#, 72 bytes

class Program{public void main(string[]args){System.Console.Beep(500);}}

NoOneIsHere

Posted 2012-11-17T18:06:35.530

Reputation: 1 916

0

k/Q (6 chars)

Bell character to stdout.

1"c"$7

skeevey

Posted 2012-11-17T18:06:35.530

Reputation: 4 139

-1

C on linux

#include <fcntl.h>
#include <linux/cdrom.h>
#include <sys/ioctl.h>

int main() {
  ioctl(open("/dev/sdb", O_RDONLY), CDROMEJECT);
}

Opens the CD-ROM door.

You may need to change sdb to whatever your optical drive's device is.

Riot

Posted 2012-11-17T18:06:35.530

Reputation: 4 639