Syntax
y=audiotrim(y,FS,[n,thr])
Input Parameter
y : | | samples |
FS : | | Sample rate |
n : | | seconds to add silence; default is 0.2 |
thr : | | threshold for silence; default is 0.01 |
Output Parameter
Examples
y=audiorecorderTL('PRO X',16000,5); audiotrim(y,16000); y=ans; soundTL(y,16000,'pro x');
Copyright 2020-2025 Tim C. Lueth. All rights reserved. The code is the property of Tim C. Lueth and may not be redistributed or modified without explicit written permission. This software may be used free of charge for academic research and teaching purposes only. Commercial use, redistribution, modification, or reverse engineering is strictly prohibited. Access to source code is restricted and granted only under specific agreements. For licensing inquiries or commercial use, please contact: Tim C. Lueth
Algorithm (Workflow)
This algorithm is designed to trim an audio signal and add a short break of silence at the end. It is part of the SolidGeometry library and was introduced in version 4.9.
Input Parameters
- y: The audio samples to be processed.
- FS: The sample rate of the audio signal.
- n: The duration of silence to add at the end of the trimmed audio, in seconds. The default value is 0.2 seconds.
- thr: The threshold for determining silence in the audio signal. The default value is 0.01.
Output
- y: The processed audio signal with silence trimmed and a break added.
Algorithm Steps
- Calculate the original length of the audio signal in seconds using
ol = size(y,1)/FS
.
- Retrieve the parameter
n
using getfuncparams
, defaulting to 0.2 seconds, and convert it to samples by multiplying with FS
.
- Retrieve the parameter
thr
using getfuncparams
, defaulting to 0.01.
- Find indices
xi
where the absolute value of the audio signal is less than the threshold thr
.
- Calculate
ai
as the difference between consecutive indices in xi
using circshift
.
- Identify the last index
bi
where the difference is greater than zero, indicating the end of a silent segment.
- If
bi
is not empty, trim the audio signal at the last silent index lst
and append n
samples of silence.
- If
bi
is empty, set the output y
to an empty array.
- Calculate the new length of the audio signal in seconds using
nl = size(y,1)/FS
.
- If no output is requested, print the reduction in audio length and play the sound using
sound(y,FS)
.
Algorithm explaination created using ChatGPT on 2025-08-19 01:01. (Please note: No guarantee for the correctness of this explanation)
Last html export of this page out of FM database by TL: 2025-09-21