Difference between revisions of "Libcanberra"

From ArchWiki
Jump to: navigation, search
(New article about libcanberra with some example code)
 
(Apply style guides)
Line 4: Line 4:
 
==Installation==
 
==Installation==
  
The {{Pkg|libcanberra}} package is available from the Extra repository. Install libcanberra from a terminal with the following command:
+
Libcanberra can be installed with the package {{Pkg|libcanberra}}, available in the [[Official Repositories]].
{{Cli|# pacman -S libcanberra}}
+
{{Note|Usually you don't have to install libcanberra explicitly, since all applications that requires libcanberra depends on it.}}
+
  
[[ALSA]] backend is included in libcanberra package, [[GStreamer]] and [[PulseAudio]] backends can be installed optionally as separated packages:
+
You have to choose a backend to play sounds:
{{Cli|# pacman -S libcanberra-gstreamer libcanberra-pulse}}
+
*[[ALSA]] backend is included in {{Pkg|libcanberra}} package
 +
*[[GStreamer]] backend can be installed with package {{Pkg|libcanberra-gstreamer}}, available in the [[Official Repositories]].
 +
*[[PulseAudio]] backend can be installed with package {{Pkg|libcanberra-pulse}}, available in the [[Official Repositories]].
 +
*[[OSS]] backend can be installed with the package {{AUR|libcanberra-oss}}, available in the [[Arch User Repository]].
  
[[OSS]] backend is available in {{AUR|libcanberra-oss}} package from AUR.
+
Also, you have to install a sound theme in order to hear any event sound:
 
+
*The default sound theme is 'freedesktop', which can be installed with the package {{Pkg|sound-theme-freedesktop}}, available in the [[Official Repositories]].
In order to hear any event sound, you have to install a sound theme. The default sound theme is {{Pkg|sound-theme-freedesktop}}, which can be installed by the following command:
+
*Alternatively, you can install {{AUR|ubuntu-sounds}} from AUR, available in the [[Arch User Repository]].
{{Cli|# pacman -S sound-theme-freedesktop}}
+
Alternatively you could install {{AUR|ubuntu-sounds}} from AUR, and modify your sound theme setting.
+
  
 
==Tips & Tricks==
 
==Tips & Tricks==
Line 24: Line 23:
 
====Bash====
 
====Bash====
 
*Dependency: {{Pkg|libcanberra}}
 
*Dependency: {{Pkg|libcanberra}}
{{File|hallo_world.sh|<nowiki>#!/bin/bash
+
{{hc|hallo_world.sh|<nowiki>#!/bin/bash
 
canberra-gtk-play -i phone-incoming-call -d "Hallo world"</nowiki>}}
 
canberra-gtk-play -i phone-incoming-call -d "Hallo world"</nowiki>}}
  
 
====C====
 
====C====
 
*Dependency: {{Pkg|libcanberra}}
 
*Dependency: {{Pkg|libcanberra}}
*Build with: {{Codeline|gcc -o hallo_world `pkg-config --cflags --libs glib-2.0 libcanberra` hallo_world.c}}
+
*Build with: {{ic|gcc -o hallo_world `pkg-config --cflags --libs glib-2.0 libcanberra` hallo_world.c}}
{{File|hallo_world.c|<nowiki>#include <glib.h>
+
{{hc|hallo_world.c|<nowiki>#include <glib.h>
 
#include <canberra.h>
 
#include <canberra.h>
 
void main () {
 
void main () {
Line 45: Line 44:
 
*Dependency: {{Pkg|libcanberra}}
 
*Dependency: {{Pkg|libcanberra}}
 
*Makedependency: {{Pkg|vala}}
 
*Makedependency: {{Pkg|vala}}
*Build with: {{Codeline|valac --pkg libcanberra hallo_world.gs}}
+
*Build with: {{ic|valac --pkg libcanberra hallo_world.gs}}
{{File|hallo_world.gs|<nowiki>uses
+
{{hc|hallo_world.gs|<nowiki>uses
 
Canberra
 
Canberra
 
init
 
init
Line 59: Line 58:
 
*Dependency: {{Pkg|libcanberra}}
 
*Dependency: {{Pkg|libcanberra}}
 
*Makedependency: {{Pkg|vala}}
 
*Makedependency: {{Pkg|vala}}
*Build with: {{Codeline|valac --pkg libcanberra hallo_world.vala}}
+
*Build with: {{ic|valac --pkg libcanberra hallo_world.vala}}
{{File|hallo_world.vala|<nowiki>using Canberra;
+
{{hc|hallo_world.vala|<nowiki>using Canberra;
 
public class HalloWorld {
 
public class HalloWorld {
 
static void main () {
 
static void main () {

Revision as of 06:31, 4 November 2011

Libcanberra is a simple abstract interface for playing event sounds. It implements the XDG Sound Theme and Naming Specifications for generating event sounds on free desktops, such as GNOME. Further description here

Installation

Libcanberra can be installed with the package libcanberra, available in the Official Repositories.

You have to choose a backend to play sounds:

Also, you have to install a sound theme in order to hear any event sound:

Tips & Tricks

Write your own canberra app

You can write your own libcanberra sound events easily in some programming languages, or you can simply use bash.

Bash

hallo_world.sh
#!/bin/bash
canberra-gtk-play -i phone-incoming-call -d "Hallo world"

C

  • Dependency: libcanberra
  • Build with: gcc -o hallo_world `pkg-config --cflags --libs glib-2.0 libcanberra` hallo_world.c
hallo_world.c
#include <glib.h>
#include <canberra.h>
void main () {
	ca_context * Hallo;
	ca_context_create (&Hallo);
	ca_context_play (Hallo, 0,
		CA_PROP_EVENT_ID, "phone-incoming-call",
		CA_PROP_EVENT_DESCRIPTION, "Hallo world",
		NULL);
	g_usleep (2000000);
}

Genie

  • Dependency: libcanberra
  • Makedependency: vala
  • Build with: valac --pkg libcanberra hallo_world.gs
hallo_world.gs
uses
	Canberra
init
	Hallo: Context
	Context.create(out Hallo)
	Hallo.play (0,
		PROP_EVENT_ID, "phone-incoming-call",
		PROP_EVENT_DESCRIPTION, "Hallo world")
	Thread.usleep (2000000)

Vala

  • Dependency: libcanberra
  • Makedependency: vala
  • Build with: valac --pkg libcanberra hallo_world.vala
hallo_world.vala
using Canberra;
public class HalloWorld {
	static void main () {
	Context Hallo;
	Context.create(out Hallo);
	Hallo.play (0,
		PROP_EVENT_ID, "phone-incoming-call",
		PROP_EVENT_DESCRIPTION, "Hallo world");
	Thread.usleep (2000000);
	}
}

More Resources