Skip to content

Tutorial / チュートリアル

This tutorial will teach you the basics of the Wandas library in 5 minutes. このチュートリアルでは、Wandasライブラリの基本的な使い方を5分で学べます。

Installation / インストール

pip install wandas

Basic Usage / 基本的な使い方

1. Import the Library / ライブラリのインポート

import wandas as wd

2. Load Audio Files / 音声ファイルの読み込み

# Load a WAV file / WAVファイルを読み込む
url = "https://github.com/kasahart/wandas/raw/v0.1.6/examples/data/summer_streets1.wav"

audio = wd.read_wav(url)
print(f"Sampling rate / サンプリングレート: {audio.sampling_rate} Hz")
print(f"Number of channels / チャンネル数: {audio.n_channels}")
print(f"Duration / 長さ: {audio.duration} s")

Sampling rate / サンプリングレート: 44100 Hz
Number of channels / チャンネル数: 2
Duration / 長さ: 15.0 s

3. Visualize Signals / 信号の可視化

# Display waveform / 波形を表示
audio.describe()
2026-04-01T16:53:40.591559 image/svg+xml Matplotlib v3.10.7, https://matplotlib.org/

4. Basic Signal Processing / 基本的な信号処理

# Apply a low-pass filter (passing frequencies below 1kHz)
# ローパスフィルタを適用(1kHz以下の周波数を通過)
filtered = audio.low_pass_filter(cutoff=1000)

# Visualize and compare results
# 結果を可視化して比較
filtered.previous.plot(title="Original")
filtered.plot(title="filtered")
2026-04-01T16:53:42.172499 image/svg+xml Matplotlib v3.10.7, https://matplotlib.org/ 2026-04-01T16:53:43.619539 image/svg+xml Matplotlib v3.10.7, https://matplotlib.org/

Channel selection with query / チャンネル選択(query 引数)

get_channel can select channels using a query argument based on metadata instead of indices or labels. Supported queries: get_channel はインデックスやラベルの代わりにメタデータを用いた query 引数でチャネルを選択できます。サポートされるクエリ:

  • str: Exact match for labels / ラベルの完全一致
  • re.Pattern: Regular expression search on labels / ラベルに対する正規表現検索
  • callable(ChannelMetadata) -> bool: Metadata predicate / メタデータ述語
  • dict: Match against attributes of ChannelMetadata (can use regex for values) / ChannelMetadata の属性に対する一致(値に正規表現を使うことも可能)

Example / 例:

import re

# Get channel with label containing "acc" / ラベルに "acc" を含むチャネルを取得
cf.get_channel(0, query=re.compile(r"acc"))

# Get channel with unit 'g' using metadata predicate / メタデータ述語で取得(単位が g のチャネル)
cf.get_channel(0, query=lambda ch: ch.unit == 'g')

# Dict specification: match on model field and channel.extra key / dict 指定: model フィールド と channel.extra のキーでマッチ
cf.get_channel(0, query={"unit": "g", "gain": 0.8})

Note: Keys specified in dict are only allowed for model fields of ChannelMetadata (pydantic) or existing keys in the channel's extra. Passing unknown keys will raise a KeyError. 注意: dict で指定するキーは ChannelMetadata のモデルフィールド(pydantic)または既に存在するチャネルの extra キーのみ許容されます。不明なキーを渡すと KeyError が発生します。

Next Steps / 次のステップ

Learning Path / 学習パス

This section provides links to tutorial notebooks that demonstrate more detailed features and application examples of the Wandas library. このセクションでは、Wandasライブラリのより詳細な機能や応用例を、以下のチュートリアルノートブックを通じて学ぶことができます。