/src/phonem.m
MATLAB | 552 lines | 313 code | 107 blank | 132 comment | 28 complexity | 95dff5afdef52fa1646f1bfdc2b6e878 MD5 | raw file
- function varargout = phonem(varargin)
- % PHONEM M-file for phonem.fig
- % PHONEM, by itself, creates a new PHONEM or raises the existing
- % singleton*.
- %
- % H = PHONEM returns the handle to a new PHONEM or the handle to
- % the existing singleton*.
- %
- % PHONEM('CALLBACK',hObject,eventData,handles,...) calls the local
- % function named CALLBACK in PHONEM.M with the given input arguments.
- %
- % PHONEM('Property','Value',...) creates a new PHONEM or raises the
- % existing singleton*. Starting from the left, property value pairs are
- % applied to the GUI before phonem_OpeningFunction gets called. An
- % unrecognized property name or invalid value makes property application
- % stop. All inputs are passed to phonem_OpeningFcn via varargin.
- %
- % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
- % instance to run (singleton)".
- %
- % See also: GUIDE, GUIDATA, GUIHANDLES
-
- % Edit the above text to modify the response to help phonem
-
- % Last Modified by GUIDE v2.5 03-Mar-2008 18:02:07
-
- % Begin initialization code - DO NOT EDIT
- gui_Singleton = 1;
- gui_State = struct('gui_Name', mfilename, ...
- 'gui_Singleton', gui_Singleton, ...
- 'gui_OpeningFcn', @phonem_OpeningFcn, ...
- 'gui_OutputFcn', @phonem_OutputFcn, ...
- 'gui_LayoutFcn', [] , ...
- 'gui_Callback', []);
- if nargin & isstr(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
- % End initialization code - DO NOT EDIT
-
-
- % --- Executes just before phonem is made visible.
- function phonem_OpeningFcn(hObject, eventdata, handles, varargin)
- % This function has no output args, see OutputFcn.
- % hObject handle to figure
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % varargin command line arguments to phonem (see VARARGIN)
-
- % Choose default command line output for phonem
- handles.output = hObject;
-
- % Update handles structure
- guidata(hObject, handles);
-
- global phonemes;
- global dbConnection;
- global isVocalized;
- global speakerID;
-
- global groupID;
- global isGroupPhonems;
-
- set(handles.rbtTypeVoc, 'Value', 1);
- set(handles.rbtSPM, 'Value', 1);
- set(handles.sldVolume, 'Value', 0.7);
- isVocalized = 1;
-
- groupID = [];
- isGroupPhonems = 0;
- if nargin > 3
- isGroupPhonems = varargin{1};
- if isGroupPhonems == 1
- groupID = varargin{2};
- groupInfo = getGroupInfo(dbConnection, groupID);
-
- set(handles.txtGroupName, 'String', groupInfo.GROUP_NAME);
- set(handles.txtSpeakerSex, 'String', ...
- getSexFromId(groupInfo.SPKR_GENDER));
- age = sprintf('%d-%d', groupInfo.MIN_AGE, groupInfo.MAX_AGE);
- set(handles.txtSpeakerAge, 'String', age);
- set(handles.txtSpeakerRegion, 'String', ...
- getRegionFromId(groupInfo.REGION_ID));
-
- names = getGroupPhonemNames(dbConnection, groupID);
- else
- speakerID = varargin{2};
- names = getSpeakerPhonemNames(dbConnection, speakerID);
- fillGroupInfo(handles);
- end
- else
- fillGroupInfo(handles);
- end
-
- for n = 1:length(phonemes)
- s = get(handles.lstPhonemes, 'String');
- if isGroupPhonems == 1
- name.PHONEM_NAME{1} = names.PHONEM_NAME{n};
- else
- name.PHONEM_NAME{1} = names.PHONEM_NAME{n};
- end
- if ~isequal(name.PHONEM_NAME{1}, 'null')
- s{length(s) + 1} = sprintf('?????? /%s/', name.PHONEM_NAME{1});
- else
- s{length(s) + 1} = sprintf('?????? %d', n);
- end
- set(handles.lstPhonemes, 'String', s);
- end
- updateAxes(1, handles);
-
-
- function fillGroupInfo(handles)
-
- set(handles.txtGroupName, 'String', '-');
- set(handles.txtSpeakerSex, 'String', '-');
- set(handles.txtSpeakerAge, 'String', '-');
- set(handles.txtSpeakerRegion, 'String', '-');
-
-
- % --- Outputs from this function are returned to the command line.
- function varargout = phonem_OutputFcn(hObject, eventdata, handles)
- % varargout cell array for returning output args (see VARARGOUT);
- % hObject handle to figure
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
-
- % Get default command line output from handles structure
- varargout{1} = handles.output;
- % --- Executes during object creation, after setting all properties.
- function lstPhonemes_CreateFcn(hObject, eventdata, handles)
- % hObject handle to lstPhonemes (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: listbox controls usually have a white background on Windows.
- % See ISPC and COMPUTER.
- if ispc
- set(hObject,'BackgroundColor','white');
- else
- set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
- end
- % --- Executes on selection change in lstPhonemes.
- function lstPhonemes_Callback(hObject, eventdata, handles)
- % hObject handle to lstPhonemes (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- index = get(hObject, 'Value');
- updateAxes(index, handles);
- % --- Executes on button press in rbtTypeVoc.
- function rbtTypeVoc_Callback(hObject, eventdata, handles)
- % hObject handle to rbtTypeVoc (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global isVocalized;
-
- isVocalized = 1;
- set(handles.rbtTypeNvoc, 'Value', 0);
- set(handles.rbtTypeVoc, 'Value', 1);
- index = get(handles.lstPhonemes, 'Value');
- updateAxes(index, handles);
- % --- Executes on button press in rbtTypeNvoc.
- function rbtTypeNvoc_Callback(hObject, eventdata, handles)
- % hObject handle to rbtTypeNvoc (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global isVocalized;
-
- isVocalized = 0;
- set(handles.rbtTypeVoc, 'Value', 0);
- set(handles.rbtTypeNvoc, 'Value', 1);
- index = get(handles.lstPhonemes, 'Value');
- updateAxes(index, handles);
- % --- Executes during object creation, after setting all properties.
- function txtF0Frequency_CreateFcn(hObject, eventdata, handles)
- % hObject handle to txtF0Frequency (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: edit controls usually have a white background on Windows.
- % See ISPC and COMPUTER.
- if ispc
- set(hObject,'BackgroundColor','white');
- else
- set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
- end
- % --- Executes during object creation, after setting all properties.
- function sldVolume_CreateFcn(hObject, eventdata, handles)
- % hObject handle to sldVolume (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: slider controls usually have a light gray background, change
- % 'usewhitebg' to 0 to use default. See ISPC and COMPUTER.
- usewhitebg = 1;
- if usewhitebg
- set(hObject,'BackgroundColor',[.9 .9 .9]);
- else
- set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
- end
- % --- Executes on slider movement.
- function sldVolume_Callback(hObject, eventdata, handles)
- % hObject handle to sldVolume (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % Hints: get(hObject,'Value') returns position of slider
- % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
- % --- Executes on button press in btPhSynth.
- function btPhSynth_Callback(hObject, eventdata, handles)
- % hObject handle to btPhSynth (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- duration = str2num(get(handles.txtPlayDuration, 'String'));
-
- global phonemes;
- global audioPlayer;
- global isVocalized;
-
- index = get(handles.lstPhonemes, 'Value');
- ar_model = [1 phonemes(index).AR];
- F0 = str2num(get(handles.txtF0Frequency, 'String'));
- Fs = 8000;
- volume = get(handles.sldVolume, 'Value');
- y = synthPhonem(ar_model, F0, Fs, duration * Fs, isVocalized);
- if isVocalized == 1
- y = y / max(abs(y)) * volume;
- else
- y = y / (3 * std(y)) * volume;
- end
- audioPlayer = audioplayer(y, Fs);
- set(audioPlayer, 'UserData', handles.btPhSynth);
- set(audioPlayer, 'StopFcn', @playingStoped);
- set(audioPlayer, 'StartFcn', @playingStarted);
- play(audioPlayer);
- % --- Executes on button press in btSynthStop.
- function btSynthStop_Callback(hObject, eventdata, handles)
- % hObject handle to btSynthStop (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global audioPlayer;
- if isempty(audioPlayer)
- return;
- end
- stop(audioPlayer);
- % --- Executes on button press in btClose.
- function btClose_Callback(hObject, eventdata, handles)
- % hObject handle to btClose (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- close(handles.figPhSynth);
- % --- Executes during object creation, after setting all properties.
- function txtPlayDuration_CreateFcn(hObject, eventdata, handles)
- % hObject handle to txtPlayDuration (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles empty - handles not created until after all CreateFcns called
- % Hint: edit controls usually have a white background on Windows.
- % See ISPC and COMPUTER.
- if ispc
- set(hObject,'BackgroundColor','white');
- else
- set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
- end
- % --- If Enable == 'on', executes on mouse press in 5 pixel border.
- % --- Otherwise, executes on mouse press in 5 pixel border or over btPhSynth.
- function btPhSynth_ButtonDownFcn(hObject, eventdata, handles)
- % hObject handle to btPhSynth (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
-
- function playingStoped(varargin)
- global audioPlayer;
-
- buttonHandle = get(audioPlayer, 'UserData');
- set(buttonHandle, 'Enable', 'on');
-
- function playingStarted(varargin)
- global audioPlayer;
-
- buttonHandle = get(audioPlayer, 'UserData');
- set(buttonHandle, 'Enable', 'off');
-
- function updateAxes(phonemIndex, handles)
- global phonemes;
- global isVocalized;
-
- F0 = str2num(get(handles.txtF0Frequency, 'String'));
- ar_model = [1 phonemes(phonemIndex).AR];
- axes(handles.axesSpectr);
- cla;
- showSPM = get(handles.rbtSPM, 'Value');
- if showSPM == 1
- [h w] = freqz(1, ar_model);
- plot(w / (2 * pi), 10 * log10(abs(h) .^ 2)); %abs(h));%
- label = xlabel('????????????? ???????');
- set(label, 'FontName', 'MS Sans Serif');
- label = ylabel('???, ??');
- set(label, 'FontName', 'Arial Cyr');
- t = title('??????????? ????????? ???????? ??????');
- set(t, 'FontName', 'MS Sans Serif');
- xlim([0 0.5]);
- else
- plot(ar_model);
- t = title('???????????? ????????? ????????????');
- set(t, 'FontName', 'MS Sans Serif');
- xlim([1 length(ar_model)]);
- end
- axes(handles.axesTime);
- cla;
- y = synthPhonem(ar_model, F0, 8000, 500, isVocalized);
- plot(y);
- function txtF0Frequency_Callback(hObject, eventdata, handles)
- % hObject handle to txtF0Frequency (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- index = get(handles.lstPhonemes, 'Value');
- updateAxes(index, handles);
- % --- Executes on button press in btCnahgeName.
- function btCnahgeName_Callback(hObject, eventdata, handles)
- % hObject handle to btCnahgeName (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global phonemes;
- global dbConnection;
-
- global groupID;
- global isGroupPhonems;
-
- index = get(handles.lstPhonemes, 'Value');
- phonemID = phonemes(index).ID;
- if isGroupPhonems == 1
- name = getGroupPhonemName(dbConnection, phonemID, groupID);
- else
- name = getPhonemName(dbConnection, phonemID);
- end
-
- if isequal(name.PHONEM_NAME{1}, 'null')
- oldName.Name = '';
- else
- oldName.Name = name.PHONEM_NAME{1};
- end
- newName = PhonemName(oldName);
-
- if ~isempty(newName)
- if isGroupPhonems == 1
- updateGroupPhonemName(dbConnection, phonemID, groupID, newName);
- else
- updatePhonemName(dbConnection, phonemID, newName);
- end
- names = get(handles.lstPhonemes, 'String');
- names{index} = sprintf('?????? /%s/', newName);
- set(handles.lstPhonemes, 'String', names);
- end
-
- % --- Executes on button press in btDataExport.
- function btDataExport_Callback(hObject, eventdata, handles)
- % hObject handle to btDataExport (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global dbConnection;
- global phonemes;
-
- [fileName filePath filterIndex] = uiputfile(...
- {'*.csv', '????????? ????? (*.csv)'; ...
- '*.*', '??? ????? (*.*)'}, ...
- '????????? ???');
- if ~(isequal(fileName, 0) | isequal(filePath, 0))
- fullName = strcat(filePath, fileName);
-
- if filterIndex == 1
- index = find(fileName == '.');
- if isempty(index)
- fullName = strcat(fullName, '.csv');
- end
- end
- for n = 1:length(phonemes)
- m(n,:) = phonemes(n).AR;
- end
- dlmwrite(fullName, m, ';');
- end
- % --- Executes on button press in btShowIR.
- function btShowIR_Callback(hObject, eventdata, handles)
- % hObject handle to btShowIR (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global phonemes;
-
- phonemIndex = get(handles.lstPhonemes, 'Value');
- phonemModel = phonemes(phonemIndex).AR;
- InterPhonemIR(phonemModel);
- % --- Executes on button press in rbtSPM.
- function rbtSPM_Callback(hObject, eventdata, handles)
- % hObject handle to rbtSPM (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- set(handles.rbtSPM, 'Value', 1);
- set(handles.rbtLPC, 'Value', 0);
- index = get(handles.lstPhonemes, 'Value');
- updateAxes(index, handles);
- % --- Executes on button press in rbtLPC.
- function rbtLPC_Callback(hObject, eventdata, handles)
- % hObject handle to rbtLPC (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- set(handles.rbtSPM, 'Value', 0);
- set(handles.rbtLPC, 'Value', 1);
- index = get(handles.lstPhonemes, 'Value');
- updateAxes(index, handles);
- % --- Executes on button press in btClear.
- function btClear_Callback(hObject, eventdata, handles)
- % hObject handle to btClear (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- % speakerID = varargin{2};
- global phonemes;
- global dbConnection;
- global speakerID;
-
- global groupID;
- global isGroupPhonems;
-
- N = size(phonemes);
- order = size(phonemes(1).AR);
-
- AR_noise = [1];
- for m=1:1:order(1,2)
- AR_noise = [AR_noise;0];
- end;
-
- min_IE = 100000;
- index = 0;
- ID = 0;
- name = getPhonemNameBySpeaker(dbConnection, speakerID);
-
- for k = 1:1:N(1,2)
- IE = compareSPM(AR_noise,[1,phonemes(k).AR]'); % compareSPM([1,phoneme(k).AR]',AR_noise); %
- if IE < min_IE & isequal(name.PHONEM_NAME{k}, 'null')
- ID = phonemes(k).ID;
- index = k;
- min_IE = IE;
- end;
- end;
-
- s = sprintf('?? = %0.5g',min_IE);
- set(handles.IEtext,'String',s);
-
- if isGroupPhonems == 1
- updateGroupPhonemName(dbConnection, ID, groupID, '#');
- else
- updatePhonemName(dbConnection, ID, '#');
- end;
-
- names = get(handles.lstPhonemes, 'String');
- names{index} = sprintf('?????? /#/');
- set(handles.lstPhonemes, 'String', names);
- set(handles.lstPhonemes, 'Value', index);
- updateAxes(index, handles);
- % --- Executes on button press in btDelPhoneme.
- function btDelPhoneme_Callback(hObject, eventdata, handles)
- % hObject handle to btDelPhoneme (see GCBO)
- % eventdata reserved - to be defined in a future version of MATLAB
- % handles structure with handles and user data (see GUIDATA)
- global phonemes;
- global dbConnection;
-
- global groupID;
- global isGroupPhonems;
-
- index = get(handles.lstPhonemes, 'Value');
-
- % ???????? ??? ?? ??
- phonemID = phonemes(index).ID;
- if isGroupPhonems == 1
- deleteGroupPhonem(dbConnection, groupID);
- else
- sqlstatement = sprintf('DELETE * FROM PHONEMES WHERE PHNM_ID=%d', phonemID);
- exec(dbConnection, sqlstatement);
- end;
-
- % ???????? ??? ?? ?????? ?????
- names = get(handles.lstPhonemes, 'String');
- N = size(names);
- new_names(1:index-1) = names(1:index-1);
- new_names(index:N(1,1)-1) = names(index+1:N(1,1));
- set(handles.lstPhonemes, 'String', new_names);
-
- % ???????? ??? ?? ??????? phonemes
- phonemes(index:N(1,1)-1) = phonemes(index+1:N(1,1));
- phonemes(N(1,1)) = [];
- set(handles.IEtext,'String','');
- if index == 1
- updateAxes(index+1, handles);
- set(handles.lstPhonemes, 'Value', index+1);
- else
- updateAxes(index-1, handles);
- set(handles.lstPhonemes, 'Value', index-1);
- end;