首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在特定的时间戳中使用音频或等效声音播放音频。

在特定的时间戳中使用音频或等效声音播放音频。
EN

Stack Overflow用户
提问于 2016-10-27 23:16:22
回答 1查看 306关注 0票数 1

我正在用听觉反应来播放音频,现在我想在不同的时间戳中播放这首歌。到目前为止,我得到的是:

代码语言:javascript
复制
[testSound,Fs] = audioread('test.wav');
sound(testSound,Fs);

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

任何帮助都是非常感谢的!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-10-28 04:11:48

你可以提取出信号的一部分,以便你从5秒开始,然后播放它。简单地说,你会以取样率5倍的速度开始采样,作为起始指标,直到结束,然后播放声音:

代码语言:javascript
复制
[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,您实际上可以指定从哪里开始采样声音。您将使用上述相同的逻辑,并根据示例(示例)指定采样声音的起始和结尾。但是,您首先需要知道采样率是多少,所以您必须调用audioread两次才能获得采样率,最后是信号本身:

代码语言:javascript
复制
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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40295639

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档