0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

睡眠学習向け音声データにプログラミングで432Hz音を生成

Posted at

はじめに

YouTubeの主に英語圏の語学学習向けのチャンネルで睡眠学習(Sleeping Study)が流行っているようですが、あの暗記用のフレーズと一緒に流れている独特なBGMはどのようにして作成しているのでしょうか。調べたところ、脳波をリラックスさせて記憶に残るという周波数432Hzにしているというのです。そこで、今回は、プログラミングでBGMのサウンドを432Hzに変換するコードを試してみましたので共有いたします。

432Hzのサウンドを作成するPythonコード

今回は、Python + numpy + sounddevice + scipyで試してみました。

前準備として、以下のファイルを用意しています。
・BGMとして通常の波の音のサウンドデータ:ocean_waves.mp3
・睡眠学習で暗記したいフレーズがある音声データ:words.mp3

ポイントは、Pythonのライブラリ sounddevice を使用することです。
参考記事
公式URL https://pypi.org/project/sounddevice/

動作環境(インターネット接続可能なパソコンで今回検証)に以下のライブラリをインストールしておきます。

pip install numpy sounddevice scipy

実際に試して動作を確認してみたサンプルのPythonコードを以下に記載します。

import numpy as np
import sounddevice as sd
from scipy.io import wavfile
import librosa

# パラメータ
sample_rate = 44100  # Hz
duration = 60  # 秒(BGMの長さ)
freq = 432  # Hz

# 432Hzサイン波生成
t = np.linspace(0, duration, int(sample_rate * duration))
tone = 0.5 * np.sin(2 * np.pi * freq * t)

# 自然音(例: 波の音)を読み込み(事前にダウンロード)
natural_sound, sr = librosa.load("ocean_waves.mp3", sr=sample_rate, duration=duration)
natural_sound = 0.7 * natural_sound / np.max(np.abs(natural_sound))  # 音量正規化

# ミックス
mixed_bgm = tone * 0.4 + natural_sound * 0.6  # 音量バランス

# 単語音声(例: 仮のTTS音声)を読み込み
word_sound, sr = librosa.load("words.mp3", sr=sample_rate)
word_duration = len(word_sound) / sample_rate
interval = 10  # 単語間隔(秒)

# 単語音声を繰り返し配置
output = np.copy(mixed_bgm)
for i in range(0, int(duration // (word_duration + interval))):
    start = int(i * (word_duration + interval) * sample_rate)
    end = start + len(word_sound)
    if end < len(output):
        output[start:end] += word_sound * 1.0  # 単語音声を重ねる

# 保存
wavfile.write("output_432hz_with_words.wav", sample_rate, output)

# 再生(オプション)
sd.play(output, sample_rate)
sd.wait()

今回の検証は一旦、ここまでになります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?