Difference between revisions of "Audio"

From TSG Doc
Jump to navigation Jump to search
m
m
 
(One intermediate revision by the same user not shown)
Line 1: Line 1:
{{Under construction}}
 
 
When using audio in your experiment, especially when presenting time-critical stimuli, special care should be taken to optimize the audio settings on multiple levels (hardware, OS, script), as many things can go wrong along the way.  
 
When using audio in your experiment, especially when presenting time-critical stimuli, special care should be taken to optimize the audio settings on multiple levels (hardware, OS, script), as many things can go wrong along the way.  
  
 
This page outlines some best practices, however we advise to always consult a TSG member if you plan to run an audio experiment in the labs.
 
This page outlines some best practices, however we advise to always consult a TSG member if you plan to run an audio experiment in the labs.
  
==Audio Stimuli==
+
==Recording==
 +
When recording audio for stimuli material or as input for your experiment, please:
 +
* Use a high quality microphone, with a [https://www.audio-technica.com/en-us/support/a-brief-guide-to-microphones-whats-the-pattern/ polar pattern] suitable for your application.
 +
* Use a high quality recorder or audio interface, capable of recording at 24bit and 48kHz or higher.
 +
* Place the microphone at an appropriate distance from your subject. Set the levels so the audio does not clip (exceeding maximum volume).
 +
* Record in a quiet environment.
  
Bij het gebruik van audio bestanden is het belangrijk om ervoor te zorgen dat de bronnen gelijke instellingen hebben, zodat het afspelen consistent en van hoge kwaliteit is.
+
You can use our [[Sound Recording Lab]]s for high quality voice recording.
  
Advies voor het instellen van gelijke instellingen voor audio bestanden:
+
==Editing==
*1. '''audiobewerkingsprogramma''': Gebruik '''Audacity''' voor het bewerken en beheren van de audio bronbestanden. Audacity is een gratis en open-source audiobewerkingsprogramma dat een breed scala aan functionaliteiten biedt.
+
We recommend using Audacity for editing and converting audio files. Audacity is open-source and fairly easy to use, available here: https://www.audacityteam.org/
  
*2. '''Bestandsindeling''': Het wordt aanbevolen om gebruik te maken van het '''.wav''' formaat, omdat het een ongecomprimeerd formaat is en geen verlies van audiokwaliteit veroorzaakt.
+
===Export Settings===
 +
We recommend using the following export settings:
 +
* File format: .wav (PCM).
 +
* Sample Frequency: 44.1kHz.
 +
* Bit depth: 16 bit.
  
*3. '''Bemonsteringsfrequentie''': Zorg ervoor dat alle audio bestanden dezelfde bemonsteringsfrequentie hebben. Dit verwijst naar het aantal samples per seconde in het audiobestand. Stel de bemonsteringsfrequentie van de bron in op '''44.1 kHz''', dit is ook de instelling van windows op de labcomputer.
+
The [[Lab Computer]] audio output is also set to 16 bit, 44.1kHz. We found that this is good enough for most applications; higher settings will increase file size with limited perceivable quality gains.
  
*4. '''Bits per sample''': Verwijst naar het aantal bits dat per sample gebruikt wordt.  Een hogere bitsnelheid resulteert in een betere audiokwaliteit, maar resulteert ook in grotere bestandsgroottes. Gebruik een bitsnelheid van '''16 bits''', dit biedt een goede balans  tussen geluidskwaliteit en bestandsgrootte.
+
When using multiple audio files in your experiment, make sure they all use the same settings for consistent playback in your experiment.
  
==Windows-audioverbeteringen==
+
In Audacity, you can set up Macros to automate processing and exporting your audio files: https://manual.audacityteam.org/man/macros.html
  
Op Windows zetten we instelling '''"Enhance audio"''' uit. Het uitschakelen van audioverbeteringen geeft een nauwkeurigere en onvervalste weergave van het audio bestand. Deze instelling is standaard gedaan op de aangesloten speakers van de labcomputer, als u een extra speaker of koptelefoon aansluit zal deze instelling nog aangepast/uitgezet moeten worden.
+
==Windows Settings==
 +
Windows 10 has a habit of automatically enabling '''audio enhancements''' when connecting new speakers or headphones. These "enhancements" can distort your audio and cause timing issues. Therefore, please make sure they are turned off:
 +
# Right click sound icon on taskbar (next to clock) -> Sounds
 +
# Goto Playback tab. Select your audio output device and click "Properties"
 +
# Goto Enhancements tab. Make sure "Disable all enhancements" is checked.
 +
# Click Apply.
  
==Code voorbeeld==
+
==Playback==
=== Python ===
+
=== Psychopy ===
Hier is een voorbeeld van een Python-script in Psychopy dat een .wav bestand nauwkeurig afspeelt op basis van tijd:
+
This is an example of a Python script that plays a .wav file with high time accuracy.
 
<syntaxhighlight lang="python" line>
 
<syntaxhighlight lang="python" line>
 
from psychopy import sound, core
 
from psychopy import sound, core
Line 29: Line 42:
 
prefs.hardware['audioLib'] = ['PTB']
 
prefs.hardware['audioLib'] = ['PTB']
  
# Pad naar het audiobestand
+
# Path to audio file
audio_file = "pad_naar_audio_bestand.wav"
+
audio_file = "voice.wav"
  
# Laad het audiobestand
+
# Load audio
 
# preBuffer – integer to control streaming/buffering -1 means store all  
 
# preBuffer – integer to control streaming/buffering -1 means store all  
 
audio = sound.Sound(audio_file,preBuffer=-1)
 
audio = sound.Sound(audio_file,preBuffer=-1)
  
# Speel het audiobestand af
+
# Play audio
 
audio.play()
 
audio.play()
  
# Wacht tot het audiobestand is afgespeeld
+
# Wait for audio to finish playing
 
core.wait(audio.getDuration())
 
core.wait(audio.getDuration())
  
# Sluit het audiobestand
+
# Close audio
 
audio.stop()
 
audio.stop()
 
audio.close()
 
audio.close()
 
</syntaxhighlight>
 
</syntaxhighlight>

Latest revision as of 15:12, 20 March 2024

When using audio in your experiment, especially when presenting time-critical stimuli, special care should be taken to optimize the audio settings on multiple levels (hardware, OS, script), as many things can go wrong along the way.

This page outlines some best practices, however we advise to always consult a TSG member if you plan to run an audio experiment in the labs.

Recording

When recording audio for stimuli material or as input for your experiment, please:

  • Use a high quality microphone, with a polar pattern suitable for your application.
  • Use a high quality recorder or audio interface, capable of recording at 24bit and 48kHz or higher.
  • Place the microphone at an appropriate distance from your subject. Set the levels so the audio does not clip (exceeding maximum volume).
  • Record in a quiet environment.

You can use our Sound Recording Labs for high quality voice recording.

Editing

We recommend using Audacity for editing and converting audio files. Audacity is open-source and fairly easy to use, available here: https://www.audacityteam.org/

Export Settings

We recommend using the following export settings:

  • File format: .wav (PCM).
  • Sample Frequency: 44.1kHz.
  • Bit depth: 16 bit.

The Lab Computer audio output is also set to 16 bit, 44.1kHz. We found that this is good enough for most applications; higher settings will increase file size with limited perceivable quality gains.

When using multiple audio files in your experiment, make sure they all use the same settings for consistent playback in your experiment.

In Audacity, you can set up Macros to automate processing and exporting your audio files: https://manual.audacityteam.org/man/macros.html

Windows Settings

Windows 10 has a habit of automatically enabling audio enhancements when connecting new speakers or headphones. These "enhancements" can distort your audio and cause timing issues. Therefore, please make sure they are turned off:

  1. Right click sound icon on taskbar (next to clock) -> Sounds
  2. Goto Playback tab. Select your audio output device and click "Properties"
  3. Goto Enhancements tab. Make sure "Disable all enhancements" is checked.
  4. Click Apply.

Playback

Psychopy

This is an example of a Python script that plays a .wav file with high time accuracy.

 1from psychopy import sound, core
 2from psychopy import prefs
 3prefs.hardware['audioLib'] = ['PTB']
 4
 5# Path to audio file
 6audio_file = "voice.wav"
 7
 8# Load audio
 9# preBuffer – integer to control streaming/buffering -1 means store all 
10audio = sound.Sound(audio_file,preBuffer=-1)
11
12# Play audio
13audio.play()
14
15# Wait for audio to finish playing
16core.wait(audio.getDuration())
17
18# Close audio
19audio.stop()
20audio.close()