matlab - 使用 audioread 或等效的以特定时间戳播放音频

标签 matlab audio

我正在使用 audioread 播放音频,现在我想以不同的时间戳播放轨道。到目前为止,我所拥有的是:

[testSound,Fs] = audioread('test.wav');
sound(testSound,Fs);

是否可以以某种方式指定音轨应从例如秒 5 开始?更具体地说,我的音频样本 test.wav是 45 秒长,而不是从头开始播放声音,我想定义它应该从哪里开始播放。

任何帮助深表感谢!

最佳答案

您可以提取一部分信号,以便从 5 秒标记处开始,然后播放。简而言之,您将以 5 倍的采样率作为起始索引开始采样,一直到结束,然后播放声音:

[testSound,Fs] = audioread('test.wav'); % From your code
beginSecond = 5; % Define where you want to start playing
beginIndex = floor(beginSecond*Fs); % Find beginning index of where to sample
soundExtract = testSound(beginIndex:end, :); % Extract the signal
sound(soundExtract, Fs); % Play the sound

或者,由于您使用的是 audioread ,您实际上可以指定从哪里开始对声音进行采样。您将使用上述相同的逻辑并指定对声音进行采样的开始和结束位置 在 sample 方面 .但是,您首先需要知道采样率是多少,因此您必须调用 audioread两次获得采样率,最后是信号本身:
beginSecond = 5; % Define where you want to start playing
[~, Fs] = audioread('test.wav'); % Get sampling rate
beginIndex = floor(beginSecond*Fs); % Find beginning index of where to sample
[soundExtract, ~] = audioread('test.wav', [beginIndex inf]); % Extract out the signal from the starting point to the end of the file
sound(soundExtract, Fs); % Play the sound

关于matlab - 使用 audioread 或等效的以特定时间戳播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40295639/

相关文章:

matlab - Matlab : numerical arguments or counterexample? 中线性不等式/等式系统隐含的不等式

matlab - 如何在 matlab 中绘制多个 3d 立方体

Matlab - 绘制向量场

javascript - 如何在 cordova 移动设备上本地加载 base64 音频?

iphone - 视频混音器API?

c++ - 通过 Mex 文件与 C++ 对象交互

java - 在 Java 中将 double[][] 获取到 MATLAB 矩阵的最快方法是什么?

javascript - 资源被解释为文档,但在Chrome控制台中因MIME类型音频/mpeg错误传输,导致无法播放声音

java - 将音频剪辑保存在内存中

flash - 使用 RTMFP 与操纵的语音音频进行实时语音聊天