Video Playback: Difference between revisions
Jump to navigation
Jump to search
| Line 116: | Line 116: | ||
|} | |} | ||
=== Python === | === Python === | ||
Example demonstrating how to | Example demonstrating how to check your audio: | ||
<syntaxhighlight lang="python" line> | <syntaxhighlight lang="python" line> | ||
#!/usr/bin/env python3.10 | #!/usr/bin/env python3.10 | ||
# - | |||
import psychopy | |||
print(psychopy.__version__) | |||
import sys | |||
print(sys.version) | |||
import keyboard | |||
from psychopy import prefs | |||
from psychopy import visual, core, event | |||
from psychopy.sound import backend_ptb | |||
# 0: No special settings (default, not optimized) | |||
# 1: Try low-latency but allow some delay | |||
# 2: Aggressive low-latency | |||
# 3: Exclusive mode, lowest latency but may not work on all systems | |||
backend_ptb.SoundPTB.latencyMode = 2 | |||
prefs.hardware['audioLib'] = ['PTB'] | |||
prefs.hardware['audioDriver'] = ['ASIO'] | |||
prefs.hardware['audioDevice'] = ['ASIO4ALL v2'] | |||
from psychopy import sound | |||
# --- OS-level audio device sample rate --- | |||
default_output = sd.query_devices(kind='output') | |||
print("\nDefault output device info (OS level):") | |||
print(f" Name: {default_output['name']}") | |||
print(f" Default Sample Rate: {default_output['default_samplerate']} Hz") | |||
print(f" Max Output Channels: {default_output['max_output_channels']}") | |||
# Confirm the audio library and output settings | |||
print(f"Using {sound.audioLib} for sound playback.") | |||
print(f"Audio library options: {prefs.hardware['audioLib']}") | |||
print(f"Audio driver: {prefs.hardware.get('audioDriver', 'Default')}") | |||
print(f"Audio device: {prefs.hardware.get('audioDevice', 'Default')}") | |||
audio_file = 'tick_rhythm_5min.wav' | |||
print("Creating sound...") | |||
wave_file = sound.Sound(audio_file) | |||
print("Playing sound...") | |||
wave_file.play() | |||
while not keyboard.is_pressed('q'): | |||
pass | |||
# Clean up | |||
print("Exiting...") | |||
win.close() | |||
core.quit() | |||
</syntaxhighlight> | </syntaxhighlight> | ||