当前位置:网站首页>第 19 章 基于语音识别的信号灯图像模拟控制技术
第 19 章 基于语音识别的信号灯图像模拟控制技术
2022-06-22 01:02:00 【海宝7号】

随着科技的发展,道路上车流增加,从而造成了交通拥堵,环境污染,以及能源浪费等问题.一般解决办法为扩建道路等,然而由于城市人口增加道路远远不能满足车辆的增长速度.因此人们提出了智能交通系统,利用各种检测技术和智能控制算法提高路网通行能力。毋庸置疑的是,在汽车智能技术、汽车新能源技术、汽车电子这个群雄逐鹿的赛道。智能驾驶技术的要求也在不断的提升。
智能车辆教学平台、智能网联教学平台、汽车电子教学设备、在环仿真系统,目前主流的系统有很多,常用的基础部分和算法开发,智能驾驶模块,入门较好的还是matlab平台。MATLAB/Simulink中比较关键的两部分是:m语言的应用和搭载的各种工具箱的开发。
本文的基于语音识别的信号灯图像模拟控制技术处理,即是在matlab平台上开发的一套可视化程序的应用。
主程序如下:
function varargout = EmotionRec(varargin)
% EMOTIONREC M-file for EmotionRec.fig
% EMOTIONREC, by itself, creates a new EMOTIONREC or raises the existing
% singleton*.
%
% H = EMOTIONREC returns the handle to a new EMOTIONREC or the handle to
% the existing singleton*.
%
% EMOTIONREC('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in EMOTIONREC.M with the given input arguments.
%
% EMOTIONREC('Property','Value',...) creates a new EMOTIONREC or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before EmotionRec_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to EmotionRec_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 EmotionRec
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @EmotionRec_OpeningFcn, ...
'gui_OutputFcn', @EmotionRec_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
% End initialization code - DO NOT EDIT
% --- Executes just before EmotionRec is made visible.
function EmotionRec_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 EmotionRec (see VARARGIN)
% Choose default command line output for EmotionRec
handles.output = hObject;
addpath(fullfile(pwd, 'voicebox'));
clc;
axes(handles.axes1); cla reset; box on;
set(gca, 'XTick', [], 'YTick', [], ...
'XTickLabel', '', 'YTickLabel', '', 'Color', [0.7020 0.7804 1.0000]);
set(handles.axes2, 'XTick', [], 'YTick', [], ...
'XTickLabel', '', 'YTickLabel', '', 'Color', [0.7020 0.7804 1.0000], ...
'Box', 'On');
handles.dirName = 0;
handles.S = 0;
handles.fileurl = 0;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes EmotionRec wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = EmotionRec_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 on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% 载入语音库
% 数据库路径
dirName = './wav/Database';
dirName = uigetdir(dirName);
if isequal(dirName, 0)
return;
end
msgbox(sprintf('载入%s成功!', dirName), '提示信息');
handles.dirName = dirName;
guidata(hObject, handles);
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% 提取特征参数
if isequal(handles.dirName, 0)
msgbox('请选择音频库目录', '提示信息', 'modal');
return;
end
S = GetDatabase(handles.dirName);
handles.S = S;
guidata(hObject, handles);
msgbox('音频信号特征提取完毕', '提示信息', 'modal');
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% 选择测试文件
file = './wav/Test/1.wav';
[Filename, Pathname] = uigetfile('*.wav', '打开新的语音文件',...
file);
if Filename == 0
return;
end
fileurl = fullfile(Pathname,Filename);
[signal, fs] = audioread(fileurl);
axes(handles.axes1); cla reset; box on;
plot(signal); title('待识别语音信号', 'FontWeight', 'Bold');
msgbox('载入语音文件成功', '提示信息', 'modal');
handles.fileurl = fileurl;
handles.signal = signal;
handles.fs = fs;
guidata(hObject, handles);
% --- Executes on button press in pushbutton4.
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% 识别
if isequal(handles.fileurl, 0)
msgbox('请选择音频文件', '提示信息', 'modal');
return;
end
if isequal(handles.S, 0)
msgbox('请计算音频库MFCC特征', '提示信息', 'modal');
return;
end
S = handles.S;
[num, MC] = Reco(S, handles.fileurl);
result = S(num).name;
result = result(1:2);
c = 'r';
switch result
case '打开'
c = 'r';
case '关闭'
c = 'g';
case '继续'
c = 'b';
case '开始'
c = 'c';
case '停止'
c = 'y';
case '暂停'
c = 'm';
end
PlotInfo(handles.axes2, c);
msgbox('识别完成', '提示信息', 'modal');
% --- Executes on button press in pushbutton5.
function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%% 播放测试文件
if isequal(handles.fileurl, 0)
msgbox('请选择音频文件', '提示信息', 'modal');
return;
end
sound(handles.signal, handles.fs);
% --- Executes on button press in pushbutton7.
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 发送控制命令按钮
str = get(handles.textReconResult, 'String');
if isequal(strtrim(str), '')
msgbox('无控制命令!', '提示信息', 'modal');
return;
end
str = sprintf('控制命令"%s"已发送!', str);
msgbox(str, '提示信息', 'modal');
目录函数
识别声音处理。
Z最终效果

部分子函数:
function [num, MC] = Reco(S, file)
MC = GetFeather(file);
N = [];
h = waitbar(0, '', 'Name', '音频识别...');
steps = length(MC);
for i = 1 : length(MC)
mc = MC{
i};
mindis = [];
for j = 1 : length(S)
MCJ = S(j).MC;
disk = [];
for k = 1 : length(MCJ)
mck = MCJ{
k};
disk(k) = norm(mc-mck);
end
mindis = [mindis min(disk)];
end
[mind, indd] = min(mindis(:));
N = [N indd];
waitbar(i/steps, h, sprintf('已处理:%d%%', round(i/steps*100)));
end
close(h);
Ni = [];
for i = 1 : length(S)
Ni(i) = numel(find(N == i));
end
[maxNi, ind] = max(Ni);
num = ind;
子函数
enframe.m
function f=enframe(x,win,inc)
nx=length(x);
nwin=length(win);
if (nwin == 1)
len = win;
else
len = nwin;
end
if (nargin < 3)
inc = len;
end
nf = fix((nx-len+inc)/inc);
f=zeros(nf,len);
indf= inc*(0:(nf-1)).';
inds = (1:len);
f(:) = x(indf(:,ones(1,len))+inds(ones(nf,1),:));
if (nwin > 1)
w = win(:)';
f = f .* w(ones(nf,1),:);
end
获取特征子函数
GetFeather.m
function MC = GetFeather(file, flag)
if nargin < 2
flag = 0;
end
if nargin < 1
file = '.\wav\Database\关闭\关闭_bsm.wav';
end
[signal, fs] = audioread(file);
framelength = 1024;
framenumber = fix(length(signal)/framelength);
for L = 1:framenumber;
for m = 1:framelength;
framedata(m) = signal((L-1)*framelength+m);
end
E(L) = sum(framedata.^2);
end
if flag
figure; plot(E);
end
meanE = mean(E);
startflag=0;
startnum=0;
startframe=0;
endframe = 0;
S = [];
for L = 1 : framenumber
if E(L) > meanE
startnum = startnum+1;
if startnum == 2
startframe = L-2;
startflag = 1;
end
end
if E(L) < meanE
if startflag == 1
endframe = L-1;
S = [S; startframe endframe];
startflag = 0;
startnum = 0;
end
end
end
if size(S, 1) > 1
ms = min(S(:, 1));
es = max(S(:, 2));
else
ms = S(1);
es = S(2);
end
MC = [];
snum = 1;
for i = ms : es
si = (i-1)*framelength;
ei = i*framelength;
fi = signal(si:ei);
mc = mfcc(fi,fs);
MC{
snum} = mc;
snum = snum + 1;
end
语音信号库
声音处理函数工具包
本文配套文件源码下载传送门–=>
https://download.csdn.net/download/dongbao520/85695370
边栏推荐
- Record the use process of webscraper
- How to modify the dictionary
- What does container cloud mean? What is the difference with fortress machine?
- Curl requests at the server command line
- Intranet learning notes (3)
- ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql. sock' (2)
- php-admin部署-解决全部错误
- 修改字典的方法
- 动态规划-01背包,分割等和子集,最后一块石头的重量
- pytorch中copy_()、detach()、data()和clone()操作区别小结
猜你喜欢

Cancellation meeting and automatic refund processing of message queue

颜值、空间、安全、动力齐升级,新捷途X70S 8.79万元起售上市

Riscv cache

After the counter is completed, you want to count the results whose string length is greater than 2

SQL操作:WITH表达式及其应用

Standing at the digital tuyere, how can tooling enterprises "fly"

Rational rose 安装教程

Read livedata sticky events

2022年中国手机银行年度专题分析

Planification dynamique - 01 sac à dos, partitions et sous - ensembles, poids de la dernière pierre
随机推荐
1876. substring with three different characters
Brief description of advantages and disadvantages of cloud fortress distributed cluster deployment
LCP 17. Quick calculation robot
Google multi user anti Association tool
52 classes 110 common components and frameworks
机器学习 Pytorch实现案例 LSTM案例(航班人数预测)
【NOI模拟赛】区间距离(分块,卷积)
Five years after graduation, I finally became a software testing engineer with a monthly salary of 13000
[tensorrt] video swing transformer deployment
【Proteus仿真】INT0和INT1中断计数
C语言动态内存函数的应用
Apache ActiveMQ Artemis简介
Judge whether the string type is empty and whether the list set is empty
LeetCode 5242. Best English letters with both upper and lower case
Clean, compile, build, install, package differences
容器云是什么意思?与堡垒机有什么区别?
[bit operation] leetcode1009 Complement of Base 10 Integer
类和对象(下)
Read livedata sticky events
第八届“互联网+”大赛|百度杰出架构师毕然解读产业赛道命题