#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <stdio.h>
#include <linux/soundcard.h>
#define LENGTH 1 /* how many seconds of speech to store */
#define RATE 8000 /* the sampling rate */
#define SIZE 8 /* sample size: 8 or 16 bits */
#define CHANNELS 1 /* 1 = mono 2 = stereo */
#define NUM 290000
/* this buffer holds the digitized audio */
unsigned char buf[LENGTH*RATE*SIZE*CHANNELS/8];
typedef struct WavHeader
{
unsigned char ChunkID[4];
long ChunkSize;
unsigned char Format[4];
unsigned char SubChunk[3];
long SubChunk1Size;
short AudioFormat;
short AudioChannels;
long SampleRate;
long ByteRate;
short BlockAlign;
short BitsPerSample;
char DataSubChunk[4] ;
long SubChunk2Size ;
}Wav;
Wav a;
unsigned char *Buffer;
int main()
{
int fd; /* sound device file descriptor */
int arg; /* argument for ioctl calls */
int status; /* return status of system calls */
//FILE *fp1=fopen("avisspeech.txt","w+");
FILE *fp=fopen("CallFailed.wav","r+");
FILE *fwav=fopen("new.wav","w+") ;
fread(&a,sizeof(a),1,fp);
/* open sound device */
fd = open("/dev/dsp", O_RDWR);
if (fd < 0) {
perror("open of /dev/dsp failed");
exit(1);
}
/* set sampling parameters */
arg = SIZE; /* sample size */
status = ioctl(fd, SOUND_PCM_WRITE_BITS, &arg);
if (status == -1)
perror("SOUND_PCM_WRITE_BITS ioctl failed");
if (arg != SIZE)
perror("unable to set sample size");
arg = CHANNELS; /* mono or stereo */
status = ioctl(fd, SOUND_PCM_WRITE_CHANNELS, &arg);
if (status == -1)
perror("SOUND_PCM_WRITE_CHANNELS ioctl failed");
if (arg != CHANNELS)
perror("unable to set number of channels");
arg = RATE; /* sampling rate */
status = ioctl(fd, SOUND_PCM_WRITE_RATE, &arg);
if (status == -1)
perror("SOUND_PCM_WRITE_WRITE ioctl failed");
//while (1) { /* loop until Control-C */
printf("Say something:\n");
status = read(fd, buf, sizeof(buf)); /* record some sound */
//fwrite(buf,1,sizeof(buf),fp1);
if (status != sizeof(buf))
perror("read wrong number of bytes");
printf("You said:\n");
//status = write(fd, buf, sizeof(buf)); /* play it back */
//if (status != sizeof(buf))
//perror("wrote wrong number of bytes");
/* wait for playback to complete before recording again */
//sleep(10);
//status = ioctl(fd, SOUND_PCM_SYNC, 0);
//if (status == -1)
// perror("SOUND_PCM_SYNC ioctl failed");
// }
a.SubChunk2Size=sizeof(buf);
a.ChunkSize=a.SubChunk2Size-36;
a.SampleRate=8000;
a.ByteRate=16000;
fwrite(&a,sizeof(a),1,fwav);
fwrite(buf,sizeof(buf),1,fwav);
fclose(fp);
// fclose(ft);
fclose(fwav);
//fclose(fp1);
}
周楷雯
- 粉丝: 97
- 资源: 1万+
最新资源
- 基于springboot的智能热度分析和自媒体推送平台.zip
- 基于springboot的智慧外贸平台--论文.zip
- 基于深度学习的垃圾分类系统(源码+运行部署文档+报告ppt).zip
- 基于vue的地方美食分享网站--论文.zip
- 基于vue的MOBA类游戏攻略分享平台--论文.zip
- 基于web的智慧养老平台--论文.zip
- comsol仿真模拟电双层纳米电极,扩散双电层耦合了Nernst-Planck方程和泊松方程
- Toshiba-CSW2001-5APL01
- 基于Java的超市进销存系统--论文.zip
- 基于协同过滤算法商品推荐系统.zip
- 基于Spring Boot的在线考试系统--论文.zip
- PDF转Word工具CSDN版
- 基于springboot的“智慧食堂”设计与实现--论文.zip
- 基于springboot的4S店车辆管理系统--论文.zip
- 基于SpringBoot的CSGO赛事管理系统--论文.zip
- 基于springboot的财务管理系统--论文.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈