4

Possible Duplicate:
Beep on Linux in C

I have been looking for a way to play a simple beep in Linux, but all what I found don't work.

I've tried the \a, \b \7 but anyone play the beep.

I would like to play it without the use of sound libraries, later I will change the beep for a real sound using any library, but right now I'm only interested in play a beep for testing purposes

As I said, I'm using Linux (exactly LMDE) so the easiest way of Windows (include windows.h and Beep()) can't be used.

So how could I implement this? A system call or something like that.

EDIT: I ended doing it in Java and I have it working already.

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • 1
    Are you sure your beep works in the console you're using ? Nowadays it generally flashes the console window, or -better yet- do nothing at all. – slaphappy Oct 16 '12 at 16:37
  • Now that you said it, I just enabled the alert sound and tried for example backspace without nothing to delete, and it doesn't play the beep either. –  Oct 16 '12 at 16:44
  • toot is a cross-platform C file that try to call several sound generators to produce the beep. http://github.com/vareille/toot – renataflow Nov 11 '17 at 06:15

2 Answers2

4

Try including ncurses.h

#include <ncurses.h>

beep();

compile with the -lncurses flag

Reference : http://invisible-island.net/ncurses/man/curs_beep.3x.html

Also this question : make sounds (beep) with c++

Edit:

try this command line

sudo sh -c "echo -e '\a' > /dev/console"

Also try the code given at http://www.linuxplayer.org/2010/04/beep-your-pc-speaker-in-linux

int ms = 5000;
int freq = 440;
ioctl(fd, KDMKTONE, (ms<<16 | 1193180/freq));
Community
  • 1
  • 1
Amitd
  • 4,769
  • 8
  • 56
  • 82
  • 1
    Nothing.. no way. But the beep itself works because in a terminal I run "beep" and it sounds. –  Oct 17 '12 at 09:31
  • @Elemenophee i have added few more solutions after edit.. please try them too. – Amitd Oct 17 '12 at 12:21
  • Thanks for help but as I said in the edit, I switched to Java and did it using the sound libraries already, so I skipped the step of use beep for testing. –  Oct 17 '12 at 16:05
  • the last link is dead – Luke_ Feb 17 '21 at 19:53
0

Have you tried echo -e "\a"?
You might also try: echo -ne '\007'

Also there is a beep command-line tool that you should be able to install using your distributions package management system.

It should cause the terminal to emit a beep.
I've tested it on a few Linux distributions and seems to work correctly.

Chimera
  • 5,884
  • 7
  • 49
  • 81