File size: 634 Bytes
0338d23 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
from typing import Optional
import numpy as np
def generate_binaural_beats(
base_freq: int,
beat_freq: int,
duration: int,
fs: Optional[int] = 44100,
) -> tuple[np.ndarray, int]:
n_samples: int = int(fs * duration)
t: np.ndarray = np.arange(n_samples) / fs
left_ear: np.ndarray = np.sin(2 * np.pi * base_freq * t)
right_ear: np.ndarray = np.sin(2 * np.pi * (base_freq + beat_freq) * t)
stereo_sound: np.ndarray = np.vstack((left_ear, right_ear)).T
stereo_normalized: np.ndarray = np.int16(
(stereo_sound / np.max(np.abs(stereo_sound))) * 32767
)
return stereo_normalized, fs
|