AudioStream

AudioStream[source]

creates a new AudioStream object from source.

AudioStream[id]

is an object that represents a unique audio stream.

Details and Options

  • AudioStream is a handle to an Audio object or a device to programmatically control playback or recording of audio signals.
  • The source can be either of the following:
  • audioa stream to play back a single audio signal
    {audio1,audio2,}a stream to play back a list of audio signals
    funca stream generated from the function func
    deva stream recorded from the audio input device dev
  • The function func operates on a buffer of time values and for each time it should return a scalar or a vector of numeric values.
  • Use AudioPlay to start playing back the stream.
  • Use AudioRecord to start recording the stream.
  • Use AudioPause or AudioStop to pause or stop the playback or the recording.
  • The dev can be any available input audio device from $AudioInputDevices.
  • Use Audio[astream] to create an Audio object from a recorded stream.
  • The following options can be specified:
  • AudioChannelAssignment Inheritedhow to assign audio channels to outputs
    AudioOutputDevice Inheritedaudio output device to use for playback
    Looping Falsewhether to loop the playback
    SampleRate Automaticsampling rate
    SoundVolume Automaticsound volume
  • A property of an audio stream astream can be obtained using astream["prop"].
  • It is possible to set values of properties with astream["prop"]=val.
  • Some properties of the playback stream include:
  • "AudioChannelAssignment"how to assign audio channels to outputs
    "AudioOutputDevice"audio output device to use for playback
    "BufferSize"number of samples in each buffer
    "CurrentAudio"snippet of the current audio
    "ID"the stream ID
    "Looping"whether to loop the playback
    "Position"position of the playback given as a time Quantity
    "SampleRate"number of samples per second
    "SoundVolume"sound volume
    "Status"status of the stream
  • Possible settings for "Status" include "Playing", "Recording", "Paused" or "Stopped".
  • Additional properties for AudioStream[{audio1,audio2,}]:
  • "CurrentTrack"index of the track being played
    "Ordering"ordering used to play back tracks
    "Duration"duration of the current tracks
    "Durations"durations of all tracks
    "TrackCount"number of tracks
  • Additional property for AudioStream[func]:
  • "Function"the generator function
  • Additional properties for AudioStream[dev]:
  • "AudioInputDevice"audio input device to use for recording
    "GeneratedAssetLocation"path to the file that will store the recorded audio
    "RecordedAudio"an Audio object containing the recording
  • Functions such as Join, Append, AppendTo and Drop can be used to modify an AudioStream object.

Examples

open allclose all

Basic Examples  (3)

Create an AudioStream object from an audio object:

Play the audio stream:

Create an AudioStream object from an input device:

Record the stream:

Stop the recording:

Create an AudioStream object from a function:

Play the AudioStream:

Stop the playback:

Scope  (17)

Basic Uses  (5)

Create two separate streams from an audio object:

The two streams are independent. Play one after 0.5 seconds from the beginning of the other one:

Check for available stream properties:

Get the property values of an audio stream:

Set the "Position" property:

Play from the selected point:

Modify properties while playing an audio stream:

The buffer size is inherited from the system option:

Playback Streams  (7)

Inspect the properties of an AudioStream created from an Audio object:

Create an AudioStream from a list of Audio objects:

Play the audio stream:

Inspect the properties of an AudioStream created from a list of Audio objects:

Get the list of available properties:

Get the values for all available properties:

Create an AudioStream from a list of Audio objects and specify an ordering:

Change the ordering:

Play the stream with the specified ordering:

Create an AudioStream from a list of Audio objects and set some of the properties:

Change the "CurrentTrack" property and play the AudioStream:

Audio streams can be extended using Append. Generate an audio stream of two audio signals:

Create another audio signal:

Append the new audio signal to the stream:

Play back the resulting stream:

Audio streams can be combined. Generate two audio streams:

Join two audio streams:

Play back the resulting stream:

Generator Streams  (4)

Inspect the properties of an AudioStream created from a function:

Create an AudioStream from a function and record the generated signal:

Stop the recording:

Retrieve the recorded signal:

With functions that return arrays of depth 2, the first dimension is interpreted as the number of channels:

Create an AudioStream from a function:

Change the function during playback:

Input Streams  (1)

Inspect the properties of an AudioStream created from an input device:

Options  (6)

AudioChannelAssignment  (1)

By default, the AudioChannelAssignment is inherited from the corresponding Audio object:

It is possible to set the AudioStream to a different channel assignment:

Note that the channel assignment of the original audio object stays the same:

AudioOutputDevice  (1)

By default, the AudioOutputDevice is inherited from the corresponding Audio object:

It is possible to set the AudioStream to a different device using the AudioOutputDevice option:

Looping  (1)

By default, Looping is 1:

Play the stream twice:

The value of the Looping option does not need to be an integer:

SampleRate  (2)

Use the SampleRate option to control the sample rate of a generator AudioStream:

Use the SampleRate option to control the sample rate of an input AudioStream:

SoundVolume  (1)

By default, the SoundVolume is inherited from the corresponding Audio object:

It is possible to set the AudioStream to a different volume using the SoundVolume option:

Applications  (4)

Build a basic GUI:

Display a gauge with the RMS amplitude of a signal while it is playing:

Define a function to plot the loudness as a position on a horizontal gauge:

Display the gauge dynamically:

Stop the stream:

Display the power spectrum of a signal while it is playing:

Define a function for the display of the power spectrum:

Display the power spectrum dynamically:

Stop the stream:

Create an AudioStream from a function that uses only binary operations:

Control some parameter dynamically using sliders:

Properties & Relations  (2)

Use AudioPlay to create and start playing an audio stream:

Use AudioRecord to create and start a recording audio stream:

Possible Issues  (2)

If the audio is choppy, try increasing the buffer size:

It is not possible to set the "Position" property in the case of an input stream:

Wolfram Research (2017), AudioStream, Wolfram Language function, https://reference.wolfram.com/language/ref/AudioStream.html (updated 2021).

Text

Wolfram Research (2017), AudioStream, Wolfram Language function, https://reference.wolfram.com/language/ref/AudioStream.html (updated 2021).

CMS

Wolfram Language. 2017. "AudioStream." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2021. https://reference.wolfram.com/language/ref/AudioStream.html.

APA

Wolfram Language. (2017). AudioStream. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/AudioStream.html

BibTeX

@misc{reference.wolfram_2024_audiostream, author="Wolfram Research", title="{AudioStream}", year="2021", howpublished="\url{https://reference.wolfram.com/language/ref/AudioStream.html}", note=[Accessed: 07-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_audiostream, organization={Wolfram Research}, title={AudioStream}, year={2021}, url={https://reference.wolfram.com/language/ref/AudioStream.html}, note=[Accessed: 07-November-2024 ]}