GEC6818开发板JPG图像显示 | 开发板实现录音
- 一.GEC6818开发板JPG图像显示
- 1.jpg图片特性
- 2.如何解压缩jpg图片
- 1.对jpegsrc.v8c.tar.gz进行arm移植
- 2.进入~/jpeg-8c对jpeg库进行配置
- 3.编译
- 4.安装,将动态库存放到 /home/gec/armJPegLib
- 5.清空编译记录
- 6.自己查看下 /home/gec/armJPegLib目录下是否有4个目录
- 7.将图片和程序下载到开发板运行即可
- 二.开发板设置ip
- 三.tftp使用
- 四.运行程序显示图片的时候遇到以下问题
- 五.禁用开发板开机自动执行原QT程序
- 六.科大讯飞离线语音识别包Linux_aitalk_exp1227_1398d7c6运行demo程序
- 六.开发板实现录音
- 1.将alsa.tar.gz下载到开发板并解压到根目录
- 2.设置alsa库环境变量
- 3.生效该脚本文件
- 4.查看环境变量有没有alsa库
- 5.指定ALSA库的配置文件
- 6.在开发板创建脚本 vi installAlsaNote.sh ,按i按键添加以下内容,然后按:wq退出
- 7.修改脚本权限
- 8.运行脚本,注意每次掉电后需要重新运行
- 9.录音
- 10.播放音频
- 源码
- asr_offline_sample.c
- myhead.h
- Makefile
一.GEC6818开发板JPG图像显示
1.jpg图片特性
体积小,使用到数据结构里面的
霍夫曼树(哈夫曼树)
对数据进行压缩
2.如何解压缩jpg图片
1.对jpegsrc.v8c.tar.gz进行arm移植
移植方式如下:
1.将jpegsrc.v8c.tar.gz解压缩到ubuntu ~
tar -zxvf jpegsrc.v8c.tar.gz -C ~ // -C 指定解压缩的位置
2.进入~/jpeg-8c对jpeg库进行配置
./configure --host=arm-linux --prefix=/home/gec/armJPegLib
--host=arm-linux : 指定编译的环境,arm平台
--prefix=/home/gec/armJPegLib : 指定动态库存放的路径
3.编译
make
4.安装,将动态库存放到 /home/gec/armJPegLib
make install
5.清空编译记录
make clean
6.自己查看下 /home/gec/armJPegLib目录下是否有4个目录
bin include lib share
7.将图片和程序下载到开发板运行即可
二.开发板设置ip
// 临时静态设置ip设置,每次都需要设置
ifconfig eth0 192.168.24.xxx(自己分配的ip)
// 永久ip设置
vi /etc/profile
设置ip
ifconfig eth0 192.168.24.xxx(自己分配的ip)
参数如下:
ifconfig lo 127.0.0.1 up
ifconfig eth0 up
ifconfig eth0 192.168.24.xxx
保存退出,重启开发板
// 自动获取ip(慎重使用)
udhcpc
三.tftp使用
1.从飞秋下载tftp工具,解压,打开tftp32.exe
2.点击浏览选择需要下载的文件所对应的目录
3.在开发板CRT软件,执行一下命令进行下载程序
tftp 192.168.1.xxx -g -r main(需要下载的程序)
解释:
192.168.1.xxx : 电脑主机ip,注意不是开发板的ip
-g -r : 从电脑下载内容到开发板
-p -l : 将文件从开发板上传到电脑
四.运行程序显示图片的时候遇到以下问题
/main: error while loading shared libraries: libjpeg.so.8: cannot open shared object file: No such file or directory
将 libjpeg.so.8下载到开发板的/lib
tftp 192.168.1.xxx -g -r libjpeg.so.8
cp libjpeg.so.8 /lib
五.禁用开发板开机自动执行原QT程序
vi /etc/profile
将以下两行程序注释
#cd /IOT
#./iot &
保存退出,重启开发板 reboot
六.科大讯飞离线语音识别包Linux_aitalk_exp1227_1398d7c6运行demo程序
1.进入Linux_aitalk_exp1227_1398d7c6/asr_offline_sample/asr_offline_sample
2.sudo cp Linux_aitalk_exp1227_1398d7c6/libs/x64/libmsc.so /lib 只需要拷贝一遍即可
3.编译程序
./64_bitmake.sh
4.编译后生成的可执行程序存放在 Linux_aitalk_exp1227_1398d7c6/bin
5.进入 Linux_aitalk_exp1227_1398d7c6/bin执行asr_offline_sample程序
./asr_offline_sample
报错
./asr_offline_sample: error while loading shared libraries: libmsc.so: cannot open shared object file: No such file or directory
注意将
sudo cp Linux_aitalk_exp1227_1398d7c6/libs/x64/libmsc.so /lib
然后重新执行程序即可
六.开发板实现录音
/alsa/bin --> arecord 录音
/alsa/bin --> aplay 播放
alsa库移植
1.将alsa.tar.gz下载到开发板并解压到根目录
tftp 192.168.24.xxx -g -r alsa.tar.gz
2.设置alsa库环境变量
/etc/init.d/rcS 与 /etc/profile
#最大的区别就是,添加完环境变量以后不需要重启开发板,只需要执行
source /etc/init.d/rcS # 即可
vi /etc/init.d/rcS
#添加以下内容
export LD_LIBRARY_PATH=/alsa/lib:$LD_LIBRARY_PATH
export PATH=$PATH:/alsa/bin
3.生效该脚本文件
source /etc/init.d/rcS
4.查看环境变量有没有alsa库
env
5.指定ALSA库的配置文件
将/alsa/share/alsa/拷贝到/usr/share/,方法如下:
cp /alsa/share/alsa/ /usr/share/ -r
将/alsa拷贝到/home/gec/,方法如下:
cp /alsa /home/gec/ -rf ---> 如果/home/gec不存在,则需要创建
6.在开发板创建脚本 vi installAlsaNote.sh ,按i按键添加以下内容,然后按:wq退出
mkdir /dev/snd
cd /dev/snd
mknod dsp c 14 3
mknod audio c 14 4
mknod mixer c 14 0
mknod controlC0 c 116 0
mknod seq c 116 1
mknod pcmC0D0c c 116 24
mknod pcmC0D0p c 116 16
mknod pcmC0D1c c 116 25
mknod pcmC0D1p c 116 17
mknod timer c 116 33
7.修改脚本权限
chmod 777 installAlsaNote.sh
8.运行脚本,注意每次掉电后需要重新运行
./installAlsaNote.sh
9.录音
(注意录音的时候不需要接耳机,因为开发板自带有麦克风,麦克风的位置在耳机口后面)
arecord -d3 -c1 -r16000 -twav -fS16_LE abc.wav
-d, --duration=# interrupt after # seconds ---> 录音的秒数
-c, --channels=# channels ---> 音轨
-r, --rate=# sample rate ---> 采样频率
-t, --file-type TYPE file type (voc, wav, raw or au) ---> 封装的格式
-f, --format=FORMAT sample format (case insensitive) ---> 量化位数
abc.wav : 是生成的录音文件
10.播放音频
aplay abc.wav
abc.wav : 是生成的录音文件
源码
asr_offline_sample.c
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h> /* superset of previous */
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "../../include/qisr.h"
#include "../../include/msp_cmn.h"
#include "../../include/msp_errors.h"
#define SAMPLE_RATE_16K (16000)
#define SAMPLE_RATE_8K (8000)
#define MAX_GRAMMARID_LEN (32)
#define MAX_PARAMS_LEN (1024)
const char * ASR_RES_PATH = "fo|res/asr/common.jet"; //离线语法识别资源路径
const char * GRM_BUILD_PATH = "res/asr/GrmBuilld"; //构建离线语法识别网络生成数据保存路径
const char * GRM_FILE = "call.bnf"; //构建离线识别语法网络所用的语法文件
const char * LEX_NAME = "contact"; //更新离线识别语法的contact槽(语法文件为此示例中使用的call.bnf)
typedef struct _UserData {
int build_fini; //标识语法构建是否完成
int update_fini; //标识更新词典是否完成
int errcode; //记录语法构建或更新词典回调错误码
char grammar_id[MAX_GRAMMARID_LEN]; //保存语法构建返回的语法ID
}UserData;
const char *get_audio_file(void); //选择进行离线语法识别的语音文件
int build_grammar(UserData *udata); //构建离线识别语法网络
int update_lexicon(UserData *udata); //更新离线识别语法词典
int run_asr(UserData *udata); //进行离线语法识别
const char* get_audio_file(void)
{
char key = 0;
while(key != 27) //按Esc则退出
{
printf("请选择音频文件:\n");
printf("1.打电话给丁伟\n");
printf("2.打电话给黄辣椒\n");
printf("3.打电话给奥巴马\n");
key = getchar();
getchar();
switch(key)
{
case '1':
printf("\n1.打电话给丁伟\n");
return "wav/ddhgdw.pcm";
case '2':
printf("\n2.打电话给黄辣椒\n");
return "wav/ddhghlj.pcm";
case '3':
printf("\n3.打电话给奥巴马\n");
return "wav/ddhgabm.pcm";
default:
continue;
}
}
exit(0);
return NULL;
}
int build_grm_cb(int ecode, const char *info, void *udata)
{
UserData *grm_data = (UserData *)udata;
if (NULL != grm_data) {
grm_data->build_fini = 1;
grm_data->errcode = ecode;
}
if (MSP_SUCCESS == ecode && NULL != info) {
printf("构建语法成功! 语法ID:%s\n", info);
if (NULL != grm_data)
snprintf(grm_data->grammar_id, MAX_GRAMMARID_LEN - 1, info);
}
else
printf("构建语法失败!%d\n", ecode);
return 0;
}
int build_grammar(UserData *udata)
{
FILE *grm_file = NULL;
char *grm_content = NULL;
unsigned int grm_cnt_len = 0;
char grm_build_params[MAX_PARAMS_LEN] = {NULL};
int ret = 0;
grm_file = fopen(GRM_FILE, "rb");
if(NULL == grm_file) {
printf("打开\"%s\"文件失败![%s]\n", GRM_FILE, strerror(errno));
return -1;
}
fseek(grm_file, 0, SEEK_END);
grm_cnt_len = ftell(grm_file);
fseek(grm_file, 0, SEEK_SET);
grm_content = (char *)malloc(grm_cnt_len + 1);
if (NULL == grm_content)
{
printf("内存分配失败!\n");
fclose(grm_file);
grm_file = NULL;
return -1;
}
fread((void*)grm_content, 1, grm_cnt_len, grm_file);
grm_content[grm_cnt_len] = '\0';
fclose(grm_file);
grm_file = NULL;
snprintf(grm_build_params, MAX_PARAMS_LEN - 1,
"engine_type = local, \
asr_res_path = %s, sample_rate = %d, \
grm_build_path = %s, ",
ASR_RES_PATH,
SAMPLE_RATE_16K,
GRM_BUILD_PATH
);
ret = QISRBuildGrammar("bnf", grm_content, grm_cnt_len, grm_build_params, build_grm_cb, udata);
free(grm_content);
grm_content = NULL;
return ret;
}
int update_lex_cb(int ecode, const char *info, void *udata)
{
UserData *lex_data = (UserData *)udata;
if (NULL != lex_data) {
lex_data->update_fini = 1;
lex_data->errcode = ecode;
}
if (MSP_SUCCESS == ecode)
printf("更新词典成功!\n");
else
printf("更新词典失败!%d\n", ecode);
return 0;
}
int update_lexicon(UserData *udata)
{
const char *lex_content = "丁伟\n黄辣椒";
unsigned int lex_cnt_len = strlen(lex_content);
char update_lex_params[MAX_PARAMS_LEN] = {NULL};
snprintf(update_lex_params, MAX_PARAMS_LEN - 1,
"engine_type = local, text_encoding = UTF-8, \
asr_res_path = %s, sample_rate = %d, \
grm_build_path = %s, grammar_list = %s, ",
ASR_RES_PATH,
SAMPLE_RATE_16K,
GRM_BUILD_PATH,
udata->grammar_id);
return QISRUpdateLexicon(LEX_NAME, lex_content, lex_cnt_len, update_lex_params, update_lex_cb, udata);
}
int tcp_socket=0;
int new_socket=0;
void init_network()
{
//1.初始化网络
tcp_socket = socket(AF_INET, SOCK_STREAM, 0);
//2.绑定服务器
//设置链接的服务器地址信息
struct sockaddr_in addr;
addr.sin_family = AF_INET; //IPV4 协议
addr.sin_port = htons(50000); //端口
addr.sin_addr.s_addr = inet_addr("192.168.24.35"); //服务器的IP 地址
//解决端口复用
int on=1;
setsockopt(tcp_socket,SOL_SOCKET,SO_REUSEADDR,&on,sizeof(on));
on=1;
setsockopt(tcp_socket,SOL_SOCKET,SO_REUSEPORT,&on,sizeof(on));
//2.绑定服务器地址信息
int ret=bind(tcp_socket,(struct sockaddr *)&addr,sizeof(addr));
if(ret < 0)
{
perror("");
return 0;
}
else
{
printf("绑定成功\n");
}
//3.设置服务器为监听模式
ret=listen(tcp_socket,5);
if(ret < 0)
{
perror("");
return 0;
}
else
{
printf("设置监听成功\n");
}
//4.接收客户端的链接请求
printf("等待服务器链接进来\n");
new_socket=accept(tcp_socket,NULL,NULL);
if(new_socket < 0)
{
perror("");
return 0;
}
else
{
printf("链接成功!!\n");
}
}
//设计一个从网络获取文件接口
char *get_network_file()
{
//进行文件的接收
//1.新建文件
int new_fd=open("wav/cmd.pcm",O_RDWR|O_CREAT|O_TRUNC,0777);
int all_size=0;
while(1)
{
//读取网络数据,写入到本地文件中
char buf[4096]={0};
int size = read(new_socket,buf,4096);
write(new_fd,buf,size);
all_size+= size;
if(all_size == 96000)
{
printf("接收文件完毕,开始识别\n");
break;
}
}
//关闭所有打开后的文件
close(new_fd);
return "wav/cmd.pcm";
}
int run_asr(UserData *udata)
{
char asr_params[MAX_PARAMS_LEN] = {NULL};
const char *rec_rslt = NULL;
const char *session_id = NULL;
const char *asr_audiof = NULL;
FILE *f_pcm = NULL;
char *pcm_data = NULL;
long pcm_count = 0;
long pcm_size = 0;
int last_audio = 0;
int aud_stat = MSP_AUDIO_SAMPLE_CONTINUE;
int ep_status = MSP_EP_LOOKING_FOR_SPEECH;
int rec_status = MSP_REC_STATUS_INCOMPLETE;
int rss_status = MSP_REC_STATUS_INCOMPLETE;
int errcode = -1;
//获取识别的音频文件
//asr_audiof = get_audio_file(); //主要修改这里,让他去识别我们自己的音频文件
asr_audiof = get_network_file(); //从网络中获取文件
f_pcm = fopen(asr_audiof, "rb");
if (NULL == f_pcm) {
printf("打开\"%s\"失败![%s]\n", f_pcm, strerror(errno));
goto run_error;
}
//获取音频文件的大小,分配堆空间
fseek(f_pcm, 0, SEEK_END);
pcm_size = ftell(f_pcm);
fseek(f_pcm, 0, SEEK_SET);
pcm_data = (char *)malloc(pcm_size);
if (NULL == pcm_data)
goto run_error;
//把所有的音频数据,读取到堆空间中
fread((void *)pcm_data, pcm_size, 1, f_pcm);
fclose(f_pcm);
f_pcm = NULL;
//离线语法识别参数设置
snprintf(asr_params, MAX_PARAMS_LEN - 1,
"engine_type = local, \
asr_res_path = %s, sample_rate = %d, \
grm_build_path = %s, local_grammar = %s, \
result_type = json, result_encoding = UTF-8, ",
ASR_RES_PATH,
SAMPLE_RATE_16K,
GRM_BUILD_PATH,
udata->grammar_id
);
session_id = QISRSessionBegin(NULL, asr_params, &errcode);
if (NULL == session_id)
goto run_error;
printf("开始识别...\n");
while (1) {
unsigned int len = 6400;
if (pcm_size < 12800) {
len = pcm_size;
last_audio = 1;
}
aud_stat = MSP_AUDIO_SAMPLE_CONTINUE;
if (0 == pcm_count)
aud_stat = MSP_AUDIO_SAMPLE_FIRST;
if (len <= 0)
break;
printf(">");
fflush(stdout);
errcode = QISRAudioWrite(session_id, (const void *)&pcm_data[pcm_count], len, aud_stat, &ep_status, &rec_status);
if (MSP_SUCCESS != errcode)
goto run_error;
pcm_count += (long)len;
pcm_size -= (long)len;
//检测到音频结束
if (MSP_EP_AFTER_SPEECH == ep_status)
break;
usleep(150 * 1000); //模拟人说话时间间隙
}
//主动点击音频结束
QISRAudioWrite(session_id, (const void *)NULL, 0, MSP_AUDIO_SAMPLE_LAST, &ep_status, &rec_status);
free(pcm_data);
pcm_data = NULL;
//获取识别结果
while (MSP_REC_STATUS_COMPLETE != rss_status && MSP_SUCCESS == errcode) {
rec_rslt = QISRGetResult(session_id, &rss_status, 0, &errcode);
usleep(150 * 1000);
}
printf("\n识别结束:\n");
printf("=============================================================\n");
if (NULL != rec_rslt)
{
printf("%s\n", rec_rslt);
//把结果回发给客户端
write(new_socket,rec_rslt,strlen(rec_rslt));
}
else
printf("没有识别结果!\n");
printf("=============================================================\n");
goto run_exit;
run_error:
if (NULL != pcm_data) {
free(pcm_data);
pcm_data = NULL;
}
if (NULL != f_pcm) {
fclose(f_pcm);
f_pcm = NULL;
}
run_exit:
QISRSessionEnd(session_id, NULL);
return errcode;
}
int main(int argc, char* argv[])
{
const char *login_config = "appid = 4a6e6f76"; //登录参数
UserData asr_data;
int ret = 0 ;
char c;
//初始化网络
init_network();
ret = MSPLogin(NULL, NULL, login_config); //第一个参数为用户名,第二个参数为密码,传NULL即可,第三个参数是登录参数
if (MSP_SUCCESS != ret) {
printf("登录失败:%d\n", ret);
goto exit;
}
memset(&asr_data, 0, sizeof(UserData));
printf("构建离线识别语法网络...\n");
ret = build_grammar(&asr_data);
//第一次使用某语法进行识别,需要先构建语法网络,获取语法ID,之后使用此语法进行识别,无需再次构建
if (MSP_SUCCESS != ret) {
printf("构建语法调用失败!\n");
goto exit;
}
while (1 != asr_data.build_fini)
usleep(300 * 1000);
if (MSP_SUCCESS != asr_data.errcode)
goto exit;
printf("离线识别语法网络构建完成,开始识别...\n");
while(1) //不断进行识别
{
ret = run_asr(&asr_data);
if (MSP_SUCCESS != ret) {
printf("离线语法识别出错: %d \n", ret);
goto exit;
}
}
exit:
MSPLogout();
return 0;
}
myhead.h
#ifndef _MYHEAD_H
#define _MYHEAD_H
#include <stdio.h>
#include <string.h>
#include <strings.h>
//#include <uniststat.h>
//#include <fcntld.h>
#include <fcntl.h>
#include <stdio.h> //printf scanf
#include <fcntl.h> //open write read lseek close
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <stdlib.h>
#include <linux/input.h>
#include "jpeglib.h"
#define LCD_WIDTH 800
#define LCD_HEIGHT 480
#define FB_SIZE (LCD_WIDTH * LCD_HEIGHT * 4)
#define EN_LCD_SHOW_JPG 1
// 获取触摸屏坐标
int ts(int *ts_x,int *ts_y);
// 显示jpg图片
int lcd_draw_jpg(unsigned int x,unsigned int y,const char *pjpg_path,char *pjpg_buf,unsigned int jpg_buf_size,unsigned int jpg_half);
#endif
Makefile
#common makefile header
DIR_INC = ../../include
DIR_BIN = ../../bin
DIR_LIB = ../../libs
TARGET = asr_offline_sample
BIN_TARGET = $(DIR_BIN)/$(TARGET)
CROSS_COMPILE =
CFLAGS = -g -Wall -I$(DIR_INC)
ifdef LINUX64
LDFLAGS := -L$(DIR_LIB)/x64
else
LDFLAGS := -L$(DIR_LIB)/x86
endif
LDFLAGS += -lmsc -lrt -ldl -lpthread -lstdc++
OBJECTS := $(patsubst %.c,%.o,$(wildcard *.c))
$(BIN_TARGET) : $(OBJECTS)
$(CROSS_COMPILE)gcc $(CFLAGS) $^ -o $@ $(LDFLAGS)
%.o : %.c
$(CROSS_COMPILE)gcc -c $(CFLAGS) $< -o $@
clean:
@rm -f *.o $(BIN_TARGET)
.PHONY:clean
#common makefile foot