Matlab的有关Audioplayer GUI问题 [英] Matlab Questions about Audioplayer GUI

查看:209
本文介绍了Matlab的有关Audioplayer GUI问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很新的Matlab和我试图做一个程序,其中有3个按钮。

I am quite new to Matlab and I am trying to make a program where there are 3 push buttons.

问题1:

按钮1将被链接到一个音频文件(.wav)
所以,当我preSS它,按键1将选择第一个音频文件。

Button 1 will be linked to an audio file (.wav) So when I press it, Button 1 will "select" the first audio file.

按钮2将与其他音频文件(.wav)
所以,当我preSS它,按键2将选择第二个音频文件。

Button 2 will be linked to another audio file (.wav) So when I press it, Button 2 will "select" the second audio file.

然后,我需要preSS按钮3播放选定声音文件的基础上,我把其中第一按钮(按钮1 /按钮2)

Then, I need to press Button 3 to play the sound file selected, based on which button I pushed first(Button 1/Button 2)

所以,我目前的code是这样的:结果
按钮1和2:

So my current code is like this:
Button 1 and 2:

[FileName,PathName] = uigetfile({'*.wav'},'Load Wav File');
[x,Fs] = wavread([PathName '/' FileName]);

按钮3:

player = audioplayer(x,Fs);
play(player);

好了,所以我的第一个问题是,当我运行此code,我必须手动选择文件。我也不太清楚如何使它已链接到的文件,所以我需要的那部分帮助...

Ok, so my first problem is that when I run this code, I have to manually select the file. I am not too sure how to make it already link to the file, so I need help on that part...

我的第二个问题实际上是对audioplayer ...
对于按钮3,它实际上是没有工作......没有播放声音了。
我试图声音(X,FS)但我在网上搜索,他们说我必须手动发出命令清晰的声音从继续停止.wav文件之前。

My second problem is actually about the audioplayer... For Button 3, it is actually not working... and no sound is played out. I tried sound (x,Fs) before but I search online and they say I have to manually give the command clear sound to stop the .wav file from continuing.

做的是如何解决这个问题?因为我想,如果我用一个第四个按钮与code:

How do is solve this problem? Because I think if I use a fourth button with the code:

stop(player)

它给了我一个错误。

it gives me an error.

推荐答案

我的第一个答案开始变得有点乱,所以我会在这里发表一个完全工作简单的例子。在这个界面中,有3按键(播放,暂停和停止),以及一个.wav文件出场(piano2.wav)。

My first answer is starting to get a bit messy, so i'll post here a fully working simple example. In this GUI, there are 3 pushButtons (Play, Pause and Stop), and one .wav file played (piano2.wav).

function varargout = AudioTest(varargin)

gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @AudioTest_OpeningFcn, ...
                   'gui_OutputFcn',  @AudioTest_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%      Opening function       %%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



function AudioTest_OpeningFcn(hObject, eventdata, handles, varargin)


handles.output = hObject;
handles.myPlayer=[];

% Update handles structure

guidata(hObject, handles);





function varargout = AudioTest_OutputFcn(hObject, eventdata, handles) 


varargout{1} = handles.output;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%  Executed on press of Play button   %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function Play_Callback(hObject, eventdata, handles)

[x,Fs]=wavread('piano2.wav');
handles.myPlayer=audioplayer(x,Fs);
play(handles.myPlayer);
guidata(hObject,handles);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%  Executed on press of Pause button   %%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

function Pause_Callback(hObject, eventdata, handles)


pause(handles.myPlayer);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%  Executed on press of Stop button   %%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


function Stop_Callback(hObject, eventdata, handles)

stop(handles.myPlayer);

这篇关于Matlab的有关Audioplayer GUI问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆