资源简介
Windows下局域网语音对讲程序 ,亲测可行。
代码片段和文件信息
// Sound_send.cpp : Defines the entry point for the console application.
//
#include “stdafx.h“
#include
#include
#include
#include
#include
#pragma comment(lib “ws2_32.lib“ )
#pragma comment(lib“Winmm.lib“)
#define MAXDATASIZE 10000
void readAudioBlock(HWAVEIN hWaveIn LPSTR block DWORD size);
int main(int argc char* argv[])
{
int iClientSock;
// int addr_len;
// int numbytes;
char buf[ MAXDATASIZE ];
struct sockaddr_in ClientAddr;
WSADATA WSAData;
if( WSAStartup( MAKEWORD( 2 2) &WSAData ) )
{
printf( “initializationing error!\n“ );
WSACleanup( );
exit( 0 );
}
iClientSock = socket( AF_INET SOCK_DGRAM 0 );
if( iClientSock == INVALID_SOCKET )
{
printf( “创建套接字失败!\n“ );
WSACleanup( );
exit( 0 );
}
ClientAddr.sin_family = AF_INET;
ClientAddr.sin_port = htons(4600);
ClientAddr.sin_addr.S_un.S_addr = inet_addr( “127.0.0.1“ );//记得换IP
memset( &( ClientAddr.sin_zero ) 0 sizeof( ClientAddr.sin_zero ) );
HWAVEIN hWaveIn; /* device handle */
WAVEFORMATEX wfx; /* look this up in your documentation */
// MMRESULT result;/* for waveOut return values */
/*
* first we need to set up the WAVEFORMATEX structure.
* the structure describes the format of the audio.
*/
wfx.nSamplesPerSec = 8000; /* sample rate */
wfx.wBitsPerSample = 16; /* sample size */
wfx.nChannels = 1; /* channels*/
/*
* WAVEFORMATEX also has other fields which need filling.
* as long as the three fields above are filled this should
* work for any PCM (pulse code modulation) format.
*/
wfx.cbSize = 0; /* size of _extra_ info */
wfx.wFormatTag = WAVE_FORMAT_PCM;
wfx.nBlockAlign = (wfx.wBitsPerSample >> 3) * wfx.nChannels;
wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec;
// try to open the default wave device.
if(waveInOpen(&hWaveIn WAVE_MAPPER &wfx 0 0 CALLBACK_NULL) !=MMSYSERR_NOERROR)
{
fprintf(stderr “unable to openWAVE_MAPPER device\n“);
ExitProcess(1);
}
while(1)
{
//numbytes = recvfrom( iServerSock buf MAXDATASIZE 0 ( struct sockaddr * ) & ServerAddr &addr_len );
// writeAudioBlock(hWaveOutbufnumbytes);
int t=sizeof(buf);
readAudioBlock(hWaveInbufsizeof(buf));
t=sizeof(buf);
int sendbytes=sendto(iClientSockbufsizeof(buf)0(sockaddr*)&ClientAddrsizeof(ClientAddr));
printf(“%d\t“sendbytes);
}
/*
* device is now open so print the success message
* and then close the device again.
*/
printf(“The Wave Mapper device was opened successfully!\n“);
// waveOutClose(hWaveIn);
return 0;
}
void readAudioBlock(HWAVEIN hWaveIn LPSTR block DWORD size)
{
WAVEHDR header;
/*
* initialize the block header with the size
* and pointer.
*/
ZeroMemory(&header sizeof(WAVEHDR));
header.dwBufferLength = size;
header.lpData = block;
/*
* prepare the block for playback
*/
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
....... 1139712 2014-09-16 18:35 new_\发送\Debug\Sound_send.bsc
....... 172083 2014-09-17 08:39 new_\发送\Debug\Sound_send.exe
....... 207588 2014-09-17 08:39 new_\发送\Debug\Sound_send.ilk
....... 30168 2014-09-17 08:39 new_\发送\Debug\Sound_send.obj
....... 334800 2014-09-16 18:35 new_\发送\Debug\Sound_send.pch
....... 435200 2014-09-17 08:39 new_\发送\Debug\Sound_send.pdb
....... 505105 2014-09-16 18:36 new_\发送\Debug\Sound_send.sbr
....... 1828 2014-09-16 18:35 new_\发送\Debug\StdAfx.obj
....... 4003 2014-09-16 18:35 new_\发送\Debug\StdAfx.sbr
....... 99328 2014-09-17 08:39 new_\发送\Debug\vc60.idb
....... 143360 2014-09-17 08:39 new_\发送\Debug\vc60.pdb
....... 1232 2014-09-16 16:20 new_\发送\ReadMe.txt
....... 3674 2014-09-17 08:39 new_\发送\Sound_send.cpp
....... 4584 2014-09-16 16:20 new_\发送\Sound_send.dsp
....... 543 2014-09-16 16:20 new_\发送\Sound_send.dsw
....... 41984 2014-09-17 08:39 new_\发送\Sound_send.ncb
....... 107520 2014-09-17 08:31 new_\发送\Sound_send.opt
....... 0 2014-09-17 08:39 new_\发送\Sound_send.plg
....... 297 2014-09-16 16:20 new_\发送\StdAfx.cpp
....... 769 2014-09-16 16:20 new_\发送\StdAfx.h
....... 1147904 2014-09-16 16:14 new_\接收\Debug\Sound_win.bsc
....... 172081 2014-09-16 20:46 new_\接收\Debug\Sound_win.exe
....... 237144 2014-09-16 20:46 new_\接收\Debug\Sound_win.ilk
....... 29678 2014-09-16 20:46 new_\接收\Debug\Sound_win.obj
....... 334800 2014-09-16 16:14 new_\接收\Debug\Sound_win.pch
....... 435200 2014-09-16 20:46 new_\接收\Debug\Sound_win.pdb
....... 502071 2014-09-16 16:14 new_\接收\Debug\Sound_win.sbr
....... 1792 2014-09-16 16:14 new_\接收\Debug\StdAfx.obj
....... 4000 2014-09-16 16:14 new_\接收\Debug\StdAfx.sbr
....... 91136 2014-09-16 20:46 new_\接收\Debug\vc60.idb
............此处省略18个文件信息
- 上一篇:cyclone引脚定义
- 下一篇:波动方程有限差分模拟
相关资源
- Windows无线网卡驱动的开发
- lixSniff.zip
- 语音信号识别及处理中英文翻译文献
- PCA算法.pdf(主成分分析 ( Principal
- ulipad.4.1 for linux
- 文件系统模拟 windows资源管理器模拟
- 叫号语音平台源码
- TCP/IP调试工具大合集
- 安卓 语音
- 织梦dedecms 电脑pc 移动wap 移动mip站 三
- Windows环境下32位汇编语言程序设计第
- DBViewer——Eclipse插件,测试好用
- SYN6288案例
- crond123_1070490.zip
- Apress Visual C Sharp 2010 Recipes A Problem S
- 语音信号处理(胡航)第3版.pdf
- 3dmax中bip人物动作收集一
- congzhou09_3489437.zip
- 安卓开发课件.zip
- epass1000nd Windows下开发包
- Eclipse中Git使用大全-新手必读
- MSDN中文帮助手册
- tomcat-8.5.31免安装版
- 生成 hadoop-eclipse-plugin-2.x 插件工具代
- glew-1.6.0-win64.zip
- Windows和Linux下bison和flex的安装包
- zw_NMEA_Worker.zip
- Multiple View Geometry in Computer Vision(第二
- 科大讯飞语音芯片操作例程
- IGSTK5.2.zip
评论
共有 条评论