stop
Syntax
Description
stop(
stops both playing and recording for
the as
)audiostreamer
.
Examples
Create an audiostreamer
object with the "recorder"
mode.
as = audiostreamer("recorder");
Call record
to start recording with the audiostreamer
. The audiostreamer
will record continuously until you pause
or stop
the recording. Use the MATLAB pause
function to wait for three seconds, then call stop
on the audiostreamer
object to stop recording.
record(as) pause(3) stop(as)
Call read
to get all of the available recorded audio from the audiostreamer
.
x = read(as);
Alternatively, you can call record
with a specified number of samples after which the recording will automatically stop. Calling read
with the specified number of samples will block MATLAB execution until that number of samples has been recorded.
N = 3*as.SampleRate; % 3 seconds of samples
record(as,N)
y = read(as,N);
You can use a callback function to asynchronously provide audio to the audiostreamer
to play. Define your callback as a function that generates pink noise and plays it on the audiostreamer
. The callback function takes in the audiostreamer
object and a struct containing information about the event that triggered the callback. Create an audiostreamer
object and set the PlayerFcn
callback to the myPlayerFcn
function handle.
function myPlayerFcn(obj,ev) y = randn(1024,1); play(obj,y) end as = audiostreamer; as.PlayerFcn = @myPlayerFcn;
Now calling play
on the audiostreamer
will call the PlayerFcn
callback whenever the number of samples in the output queue drops below PlayerMinSamples
.
play(as) pause(3) stop(as)
Input Arguments
The audiostreamer
object that is playing and/or recording the audio.
The audiostreamer
mode to stop, specified as
"player"
, "recorder"
, or
"both"
.
Data Types: char
| string
Version History
Introduced in R2025a
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)