「Libcanberra」の版間の差分
ナビゲーションに移動
検索に移動
Kusakata.bot (トーク | 投稿記録) 細 (文字列「http://freedesktop.org/」を「https://freedesktop.org/」に置換) |
(英語版と同期) |
||
| 5行目: | 5行目: | ||
{{Related|デスクトップ通知}} |
{{Related|デスクトップ通知}} |
||
{{Related articles end}} |
{{Related articles end}} |
||
| − | + | [http://0pointer.de/lennart/projects/libcanberra/ Libcanberra] はイベントサウンドを再生するためのシンプルな抽象インターフェイスです。GNOME などのフリーなデスクトップでイベントサウンドを流すための [https://freedesktop.org/wiki/Specifications/sound-theme-spec XDG Sound Theme and Naming Specifications] を実装しています。 |
|
==インストール== |
==インストール== |
||
| 26行目: | 26行目: | ||
gtk-sound-theme-name=freedesktop</nowiki>}} |
gtk-sound-theme-name=freedesktop</nowiki>}} |
||
| − | GNOME では、以上の設定は gnome-settings-daemon によって管理されており、GSettings の org.gnome.desktop.sound スキーマで設定を変更できます。 |
+ | GNOME では、以上の設定は gnome-settings-daemon によって管理されており、GSettings の {{ic|org.gnome.desktop.sound}} スキーマで設定を変更できます。 |
==Systemd== |
==Systemd== |
||
| − | canberra を使って起動・シャットダウン・再起動サウンドを有効にするには、 |
+ | canberra を使って起動・シャットダウン・再起動サウンドを有効にするには、{{ic|canberra-system-bootup.service}} を[[有効化]]します。 |
| + | ==canberra アプリの書き方== |
||
| − | {{ic|<nowiki># systemctl enable canberra-system-bootup.service</nowiki>}} |
||
| + | libcanberra のサウンドイベントは、[https://gi.readthedocs.io/en/latest/ GObject-Introspection] を介して [https://wiki.gnome.org/Projects/GSound GSound] を使い様々なプログラミング言語で簡単に書くことができます。また、[[bash]] からも簡単に呼び出せます。 |
||
| + | === Bash === |
||
| − | ==ヒントとテクニック== |
||
| − | |||
| − | ===canberra アプリの書き方=== |
||
| − | libcanberra のサウンドイベントは様々なプログラミング言語で簡単に書くことができます。 |
||
| − | |||
| − | '''Bash''' |
||
*依存パッケージ: {{Pkg|libcanberra}} |
*依存パッケージ: {{Pkg|libcanberra}} |
||
| − | {{hc|hello_world.sh| |
+ | {{hc|hello_world.sh|2= |
| + | #!/bin/bash |
||
| − | canberra-gtk-play -i phone-incoming-call -d "hello world"</nowiki>}} |
||
| + | canberra-gtk-play -i phone-incoming-call -d "hello world" |
||
| + | }} |
||
| + | === C === |
||
| − | '''C''' |
||
*依存パッケージ: {{Pkg|libcanberra}} |
*依存パッケージ: {{Pkg|libcanberra}} |
||
*ビルド: {{ic|gcc hello_world.c -o hello_world `pkg-config --cflags --libs glib-2.0 libcanberra`}} |
*ビルド: {{ic|gcc hello_world.c -o hello_world `pkg-config --cflags --libs glib-2.0 libcanberra`}} |
||
| − | {{hc|hello_world.c|<nowiki |
+ | {{hc|hello_world.c|<nowiki> |
| + | #include <glib.h> |
||
#include <canberra.h> |
#include <canberra.h> |
||
void main () { |
void main () { |
||
| 58行目: | 57行目: | ||
NULL); |
NULL); |
||
g_usleep (2000000); |
g_usleep (2000000); |
||
| + | return 0; |
||
}</nowiki>}} |
}</nowiki>}} |
||
| + | *依存パッケージ: {{Pkg|gsound}} |
||
| − | '''Genie''' |
||
| + | *ビルド: {{ic|gcc -o hello_world `pkg-config --cflags --libs glib-2.0 gsound` hello_world.c}} |
||
| + | {{hc|hello_world.c|2= |
||
| + | #include <glib.h> |
||
| + | #include <gsound.h> |
||
| + | int main () { |
||
| + | GSoundContext *hello = gsound_context_new(NULL, NULL); |
||
| + | gsound_context_play_simple(hello, NULL, NULL, |
||
| + | GSOUND_ATTR_EVENT_ID, "phone-incoming-call", |
||
| + | GSOUND_ATTR_EVENT_DESCRIPTION, "hello world", |
||
| + | NULL); |
||
| + | g_usleep (2000000); |
||
| + | return 0; |
||
| + | } |
||
| + | }} |
||
| + | |||
| + | === Genie === |
||
*依存パッケージ: {{Pkg|libcanberra}} |
*依存パッケージ: {{Pkg|libcanberra}} |
||
| 75行目: | 91行目: | ||
Thread.usleep (2000000)</nowiki>}} |
Thread.usleep (2000000)</nowiki>}} |
||
| + | *依存パッケージ: {{Pkg|gsound}} |
||
| − | '''Vala''' |
||
| + | *ビルド依存パッケージ: {{Pkg|vala}} |
||
| + | *ビルド: {{ic|valac --pkg gsound hello_world.gs}} |
||
| + | {{hc|hello_world.gs|2= |
||
| + | uses |
||
| + | GSound |
||
| + | init |
||
| + | var hello = new GSound.Context |
||
| + | hello.init() |
||
| + | hello.play_simple(null, |
||
| + | GSound.Attribute.EVENT_ID, "phone-incoming-call", |
||
| + | GSound.Attribute.EVENT_DESCRIPTION, "hello world") |
||
| + | Thread.usleep (2000000) |
||
| + | }} |
||
| + | === JavaScript === |
||
| + | |||
| + | * 依存パッケージ: {{Pkg|gsound}}, {{Pkg|gjs}} |
||
| + | |||
| + | {{hc|hello_world.js|2= |
||
| + | #!/usr/bin/gjs |
||
| + | const GLib = imports.gi.GLib; |
||
| + | const GSound = imports.gi.GSound; |
||
| + | |||
| + | let hello = new GSound.Context(); |
||
| + | hello.init(null); |
||
| + | hello.play_simple({ "event.id" : "phone-incoming-call", |
||
| + | "event.description" : "hello world" }, null); |
||
| + | GLib.usleep (2000000); |
||
| + | }} |
||
| + | |||
| + | === Lua === |
||
| + | |||
| + | * 依存パッケージ: {{Pkg|gsound}}, {{Pkg|lua-lgi}} |
||
| + | |||
| + | {{hc|hello_world.lua|2= |
||
| + | #!/usr/bin/lua |
||
| + | lgi = require 'lgi' |
||
| + | GLib = lgi.require('GLib') |
||
| + | GSound = lgi.require('GSound') |
||
| + | |||
| + | hello = GSound.Context() |
||
| + | hello:play_simple({ [GSound.ATTR_EVENT_ID] = "phone-incoming-call", |
||
| + | [GSound.ATTR_EVENT_DESCRIPTION] = "hello world" }) |
||
| + | GLib.usleep (2000000) |
||
| + | }} |
||
| + | |||
| + | === Perl === |
||
| + | |||
| + | * 依存パッケージ: {{Pkg|gsound}}, {{Pkg|perl-glib-object-introspection}} |
||
| + | {{hc|hello_world.pl|2= |
||
| + | #!/usr/bin/perl |
||
| + | use Glib::Object::Introspection; |
||
| + | Glib::Object::Introspection->setup ( |
||
| + | basename => 'GSound', |
||
| + | version => '1.0', |
||
| + | package => 'GSound'); |
||
| + | my $hello = GSound::Context->new; |
||
| + | $hello->play_simple({ "event.id" => "phone-incoming-call", |
||
| + | "event.description" => "hello world" }); |
||
| + | sleep (2); |
||
| + | }} |
||
| + | |||
| + | === Python === |
||
| + | |||
| + | * 依存パッケージ: {{Pkg|gsound}}, {{Pkg|python-gobject}} |
||
| + | |||
| + | {{hc|hello_world.py|2= |
||
| + | #!/usr/bin/python |
||
| + | import gi |
||
| + | gi.require_version('GSound', '1.0') |
||
| + | from gi.repository import GLib, GSound |
||
| + | |||
| + | hello = GSound.Context() |
||
| + | hello.init() |
||
| + | hello.play_simple({GSound.ATTR_EVENT_ID: "phone-incoming-call", |
||
| + | GSound.ATTR_EVENT_DESCRIPTION: "hello world"}) |
||
| + | GLib.usleep(2000000) |
||
| + | }} |
||
| + | |||
| + | === Ruby === |
||
| + | |||
| + | * 依存パッケージ: {{Pkg|gsound}}, {{AUR|ruby-gir_ffi}} |
||
| + | |||
| + | {{hc|hello_world.rb|2= |
||
| + | #!/usr/bin/ruby |
||
| + | require 'gir_ffi' |
||
| + | GirFFI.setup :GSound |
||
| + | Hello = GSound::Context.new |
||
| + | Hello.play_simple("event.id" => "phone-incoming-call", |
||
| + | "event.description" => "hello world") |
||
| + | sleep (2) |
||
| + | }} |
||
| + | |||
| + | === Vala === |
||
*依存パッケージ: {{Pkg|libcanberra}} |
*依存パッケージ: {{Pkg|libcanberra}} |
||
| 94行目: | 203行目: | ||
==参照== |
==参照== |
||
*[http://0pointer.de/lennart/projects/libcanberra/gtkdoc/ Libcanberra リファレンスマニュアル] |
*[http://0pointer.de/lennart/projects/libcanberra/gtkdoc/ Libcanberra リファレンスマニュアル] |
||
| + | *[https://developer.gnome.org/gsound/ GSound リファレンスマニュアル] |
||
2019年6月8日 (土) 13:50時点における版
Libcanberra はイベントサウンドを再生するためのシンプルな抽象インターフェイスです。GNOME などのフリーなデスクトップでイベントサウンドを流すための XDG Sound Theme and Naming Specifications を実装しています。
目次
インストール
Libcanberra は公式リポジトリの libcanberra パッケージでインストールできます。パッケージにはライブラリと GTK+ モジュールが含まれています。
サウンドを再生するためのバックエンドを選択してください:
- ALSA バックエンドは libcanberra パッケージに入っています。
- GStreamer バックエンドは公式リポジトリの libcanberra-gstreamer パッケージでインストールできます。
- PulseAudio バックエンドは公式リポジトリの libcanberra-pulse パッケージでインストールできます。
また、イベントサウンドを聞くためにはサウンドテーマをインストールする必要があります:
- デフォルトのサウンドテーマは 'freedesktop' で、公式リポジトリの sound-theme-freedesktop パッケージでインストールできます。
- もしくは、Arch User Repository から ubuntu-soundsAUR をインストールすることも可能です。
設定
デフォルトでは、GTK+ アプリケーションが起動した時に GTK+ モジュールが自動的にロードされます。ユーザーの Gtk 設定ファイルでデフォルトの設定を上書きすることができます:
$HOME/.gtkrc-2.0 and $XDG_CONFIG_HOME/gtk-3.0/settings.ini
gtk-enable-event-sounds=true gtk-enable-input-feedback-sounds=true gtk-sound-theme-name=freedesktop
GNOME では、以上の設定は gnome-settings-daemon によって管理されており、GSettings の org.gnome.desktop.sound スキーマで設定を変更できます。
Systemd
canberra を使って起動・シャットダウン・再起動サウンドを有効にするには、canberra-system-bootup.service を有効化します。
canberra アプリの書き方
libcanberra のサウンドイベントは、GObject-Introspection を介して GSound を使い様々なプログラミング言語で簡単に書くことができます。また、bash からも簡単に呼び出せます。
Bash
- 依存パッケージ: libcanberra
hello_world.sh
#!/bin/bash canberra-gtk-play -i phone-incoming-call -d "hello world"
C
- 依存パッケージ: libcanberra
- ビルド:
gcc hello_world.c -o hello_world `pkg-config --cflags --libs glib-2.0 libcanberra`
hello_world.c
#include <glib.h>
#include <canberra.h>
void main () {
ca_context * hello;
ca_context_create (&hello);
ca_context_play (hello, 0,
CA_PROP_EVENT_ID, "phone-incoming-call",
CA_PROP_EVENT_DESCRIPTION, "hello world",
NULL);
g_usleep (2000000);
return 0;
}
- 依存パッケージ: gsound
- ビルド:
gcc -o hello_world `pkg-config --cflags --libs glib-2.0 gsound` hello_world.c
hello_world.c
#include <glib.h>
#include <gsound.h>
int main () {
GSoundContext *hello = gsound_context_new(NULL, NULL);
gsound_context_play_simple(hello, NULL, NULL,
GSOUND_ATTR_EVENT_ID, "phone-incoming-call",
GSOUND_ATTR_EVENT_DESCRIPTION, "hello world",
NULL);
g_usleep (2000000);
return 0;
}
Genie
- 依存パッケージ: libcanberra
- ビルド依存パッケージ: vala
- ビルド:
valac --pkg libcanberra hello_world.gs
hello_world.gs
uses Canberra init hello: Context Context.create(out hello) hello.play (0, PROP_EVENT_ID, "phone-incoming-call", PROP_EVENT_DESCRIPTION, "hello world") Thread.usleep (2000000)
hello_world.gs
uses GSound init var hello = new GSound.Context hello.init() hello.play_simple(null, GSound.Attribute.EVENT_ID, "phone-incoming-call", GSound.Attribute.EVENT_DESCRIPTION, "hello world") Thread.usleep (2000000)
JavaScript
hello_world.js
#!/usr/bin/gjs
const GLib = imports.gi.GLib;
const GSound = imports.gi.GSound;
let hello = new GSound.Context();
hello.init(null);
hello.play_simple({ "event.id" : "phone-incoming-call",
"event.description" : "hello world" }, null);
GLib.usleep (2000000);
Lua
hello_world.lua
#!/usr/bin/lua
lgi = require 'lgi'
GLib = lgi.require('GLib')
GSound = lgi.require('GSound')
hello = GSound.Context()
hello:play_simple({ [GSound.ATTR_EVENT_ID] = "phone-incoming-call",
[GSound.ATTR_EVENT_DESCRIPTION] = "hello world" })
GLib.usleep (2000000)
Perl
- 依存パッケージ: gsound, perl-glib-object-introspection
hello_world.pl
#!/usr/bin/perl
use Glib::Object::Introspection;
Glib::Object::Introspection->setup (
basename => 'GSound',
version => '1.0',
package => 'GSound');
my $hello = GSound::Context->new;
$hello->play_simple({ "event.id" => "phone-incoming-call",
"event.description" => "hello world" });
sleep (2);
Python
- 依存パッケージ: gsound, python-gobject
hello_world.py
#!/usr/bin/python
import gi
gi.require_version('GSound', '1.0')
from gi.repository import GLib, GSound
hello = GSound.Context()
hello.init()
hello.play_simple({GSound.ATTR_EVENT_ID: "phone-incoming-call",
GSound.ATTR_EVENT_DESCRIPTION: "hello world"})
GLib.usleep(2000000)
Ruby
- 依存パッケージ: gsound, ruby-gir_ffiAUR
hello_world.rb
#!/usr/bin/ruby
require 'gir_ffi'
GirFFI.setup :GSound
Hello = GSound::Context.new
Hello.play_simple("event.id" => "phone-incoming-call",
"event.description" => "hello world")
sleep (2)
Vala
- 依存パッケージ: libcanberra
- ビルド依存パッケージ: vala
- ビルド:
valac --pkg libcanberra hello_world.vala
hello_world.vala
using Canberra;
public class HelloWorld {
static void main () {
Context hello;
Context.create(out hello);
hello.play (0,
PROP_EVENT_ID, "phone-incoming-call",
PROP_EVENT_DESCRIPTION, "hello world");
Thread.usleep (2000000);
}
}