# AudioClip

## sound AudioClip

AudioClip encapsulates an audio recording.

## Constructor

#### new AudioClip(options)

Source:
  - sound/AudioClip.js, line 20

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | ###### Properties
Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`psychoJS` | module:core.PsychoJS |  |  | the PsychoJS instance
`name` | String | <optional> | `'audioclip'` | the name used when logging messages
`format` | string |  |  | the format for the audio file
`sampleRateHz` | number |  |  | the sampling rate
`data` | Blob |  |  | the audio data, in the given format, at the given sampling rate
`autoLog` | boolean | <optional> | `false` | whether or not to log

### Extends

- PsychObject

### Members

#### (static, readonly) Engine :Symbol

Source:
  - sound/AudioClip.js, line 447

##### Properties:

Name | Type | Description
--- | --- | ---
`GOOGLE` | Symbol | Google Cloud Speech-to-Text.

Recognition engines.

##### Type:

- Symbol

#### (static, readonly) Status :Symbol

Source:
  - sound/AudioClip.js, line 460

##### Properties:

Name | Type | Description
--- | --- | ---
`CREATED` | Symbol |
`DECODING` | Symbol |
`READY` | Symbol |

AudioClip status.

##### Type:

- Symbol

### Methods

#### (protected) _base64ArrayBuffer(arrayBuffer) → {string}

Source:
  - sound/AudioClip.js, line 380

Convert an array buffer to a base64 string.

##### Parameters:

Name | Type | Description
--- | --- | ---
`arrayBuffer` |  | the input buffer

##### Returns:

the base64 encoded input buffer

Type
  string

#### (protected) _decodeAudio()

Source:
  - sound/AudioClip.js, line 297

Decode the formatted audio data (e.g. webm) into a 32bit float PCM audio buffer.

#### (protected) _GoogleTranscribe(transcriptionKey, languageCode) → {Promise}

Source:
  - sound/AudioClip.js, line 233

Transcribe the audio clip using the Google Cloud Speech-To-Text Engine.

ref: https://cloud.google.com/speech-to-text/docs/reference/rest/v1/speech/recognize

##### Parameters:

Name | Type | Description
--- | --- | ---
`transcriptionKey` | String | the secret key to the Google service
`languageCode` | String | the BCP-47 language code for the recognition, e.g. 'en-GB'

##### Returns:

a promise resolving to the transcript and associated transcription confidence

Type
  Promise

#### download()

Source:
  - sound/AudioClip.js, line 158

Offer the audio clip to the participant as a sound file to download.

#### (async) getDuration() → {Promise.<number>}

Source:
  - sound/AudioClip.js, line 117

Get the duration of the audio clip, in seconds.

##### Returns:

the duration of the audio clip

Type
  Promise.<number>

#### setVolume(volume)

Source:
  - sound/AudioClip.js, line 60

Set the volume of the playback.

##### Parameters:

Name | Type | Description
--- | --- | ---
`volume` | number | the volume of the playback (must be between 0.0 and 1.0)

#### (async) startPlayback()

Source:
  - sound/AudioClip.js, line 70

Start playing the audio clip.

#### (async) stopPlayback(fadeDurationopt)

Source:
  - sound/AudioClip.js, line 104

Stop playing the audio clip.

##### Parameters:

Name | Type | Attributes | Default | Description
--- | --- | --- | --- | ---
`fadeDuration` | number | <optional> | `17` | how long the fading out should last, in ms

#### (async) transcribe(options) → {Promise}

Source:
  - sound/AudioClip.js, line 178

Transcribe the audio clip.

##### Parameters:

Name | Type | Description
--- | --- | ---
`options` | Object | ###### Properties
Name | Type | Description
--- | --- | ---
`engine` | Symbol | the speech-to-text engine
`languageCode` | String | the BCP-47 language code for the recognition, e.g. 'en-GB'

##### Returns:

a promise resolving to the transcript and associated transcription confidence

Type
  Promise

#### upload()

Source:
  - sound/AudioClip.js, line 130

Upload the audio clip to the pavlovia server.