Microphone - for recording sound

The Microphone class provides an interface to audio recording devices connected to the computer. As of now, Psychtoolbox is required to use this feature and must be installed.

Overview

Microphone([device, sampleRateHz, channels, ...])

Details

class psychopy.sound.microphone.Microphone(device=None, sampleRateHz=None, channels=None, streamBufferSecs=2.0, maxRecordingSize=24000, policyWhenFull='warn', exclusive=False, audioRunMode=0, name='mic', recordingFolder=WindowsPath('C:/Users/psychopyci'), recordingExt='wav', audioLatencyMode=None)[source]
property audioLatencyMode
bank(tag=None, transcribe=False, **kwargs)[source]

Store current buffer as a clip within the microphone object.

This method is used internally by the Microphone component in Builder, don’t use it for other applications. Either stop() or pause() must be called before calling this method.

Parameters:
  • tag (str or None) – Label for the clip.

  • transcribe (bool or str) – Set to the name of a transcription engine (e.g. “GOOGLE”) to transcribe using that engine, or set as False to not transcribe.

  • kwargs (dict) – Additional keyword arguments to pass to transcribe().

clear()[source]

Wipe all clips. Deletes previously banked audio clips.

close()[source]
flush()[source]

Get a copy of all banked clips, then clear the clips from storage.

getClipFilename(tag, i=0)[source]

Get the filename for a particular clip.

Parameters:
  • tag (str) – Tag assigned to the clip when bank was called

  • i (int) – Index of clip within this tag (default is -1, i.e. the last clip)

Returns:

Constructed filename for this clip

Return type:

str

getRecording()[source]
property isRecBufferFull
property isRecording
property isStarted
property latencyBias
property maxRecordingSize
pause(blockUntilStopped=True, stopTime=None)[source]
property policyWhenFull

Until a file is saved, the audio data from a Microphone needs to be stored in RAM. To avoid a memory leak, we limit the amount which can be stored by a single Microphone object. The policyWhenFull parameter tells the Microphone what to do when it’s reached that limit.

Parameters:

value (str) – One of: - “ignore”: When full, just don’t record any new samples - “warn”: Same as ignore, but will log a warning - “error”: When full, will raise an error - “rolling”: When full, clears the start of the buffer to make room for new samples

poll()[source]
property recBufferSecs
record(when=None, waitForStart=0, stopTime=None)[source]
property recording
reopen()[source]
saveClips(clear=True)[source]

Save all stored clips to audio files.

Parameters:

clear (bool) – If True, clips will be removed from this object once saved to files.

setMaxRecordingSize(value)[source]
setMaxSize(value)
setPolicyWhenFull(value)[source]

Until a file is saved, the audio data from a Microphone needs to be stored in RAM. To avoid a memory leak, we limit the amount which can be stored by a single Microphone object. The policyWhenFull parameter tells the Microphone what to do when it’s reached that limit.

Parameters:

value (str) – One of: - “ignore”: When full, just don’t record any new samples - “warn”: Same as ignore, but will log a warning - “error”: When full, will raise an error - “rolling”: When full, clears the start of the buffer to make room for new samples

start(when=None, waitForStart=0, stopTime=None)[source]
stop(blockUntilStopped=True, stopTime=None)[source]
property streamBufferSecs
property streamStatus

Back to top