Files
latency_test_suit/tone.py
2025-10-15 10:38:06 +02:00

24 lines
963 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import numpy as np
import sounddevice as sd
def play_tone(frequency=440.0, duration=1.0, volume=0.2, sample_rate=44_100):
"""
Spielt einen Sinuston ab.
frequency: Hz
duration: Sekunden
volume: 0.01.0
sample_rate: Abtastrate in Hz
"""
t = np.linspace(0, duration, int(sample_rate * duration), endpoint=False)
wave = (volume * np.sin(2 * np.pi * frequency * t)).astype(np.float32)
sd.play(wave, samplerate=sample_rate, blocking=True)
if __name__ == "__main__":
import argparse
ap = argparse.ArgumentParser(description="Spiele einen Ton")
ap.add_argument("-f", "--frequency", type=float, default=440.0, help="Frequenz in Hz (z.B. 440)")
ap.add_argument("-t", "--time", type=float, default=1.0, help="Dauer in Sekunden (z.B. 1.5)")
ap.add_argument("-v", "--volume", type=float, default=0.2, help="Lautstärke 0.01.0")
args = ap.parse_args()
play_tone(args.frequency, args.time, args.volume)