資源簡介
C#利用DirectSound可以實現把PCM音頻流保存成WAV文件,進行播放。

代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Windows.Forms;
using?System.IO;
using?System.IO.Ports;
using?System.Threading;
using?wave;
using?System.Media;
namespace?語音偵聽
{
????public?partial?class?Form1?:?Form
????{
????????SerialPort?sp?=?null;
????????bool?blWrite?=?false;
????????FileStream?mWaveFile;
????????BinaryWriter?mWriter;
????????int?mSampleCount?=?0;
????????StreamWriter?sw;
????????FileStream?fs;
????????public?Thread?threadMonitorSocketsArry;
????????string?PP?=?““;
????????public?delegate?void?dlSetButton(Button?btstring?str);
????????public?Form1()
????????{
????????????InitializeComponent();
????????}
????????private?WavSC?recorder?=?null;
????????string?strPath?=?@“f:/聲音/“;
????????private?void?Form1_Load(object?sender?EventArgs?e)
????????{
????????}
????????private?void?button1_Click(object?sender?EventArgs?e)
????????{
????????????comboBox1.Items.Clear();//combobox顯示的數據
????????????string[]?str?=?SerialPort.GetPortNames();
????????????for?(int?i?=?0;?i?????????????{
????????????????string?cktt?=?str[i];
????????????????comboBox1.Items.Add(cktt);
????????????????
????????????}
????????}
????????//private?void?UpdateButton(Button?btTemp?string?str)//調用委托
????????//{
????????//????if?(btTemp.InvokeRequired)
????????//????{
????????//????????dlSetButton?dlobject?=?new?dlSetButton(UpdateButton);
????????//????????btTemp.Invoke(dlobject?btTemp?str);
????????//????}
????????//????else
????????//????{
????????//????????btTemp.Text?=?str;//顯示內容
????????//????????btTemp.Enabled?=?true;//開始使用按鈕
????????//????}
????????//}
????????private?void?button2_Click(object?sender?EventArgs?e)
????????{
????????????sp?=?new?SerialPort();
????????????sp.PortName?=?comboBox1.Text.Trim();
????????????sp.BaudRate?=?9600;
????????????sp.DataBits?=?8;
????????????sp.StopBits?=?StopBits.One;
????????????sp.Parity?=?Parity.None;
????????????sp.Open();
????????????//發(fā)送頻率信息
????????????string?strFreq?=?textBox1.Text.Trim();
????????????string?strTemp?=?“AT+DMOSETGROUP=1“?+?strFreq?+?““?+?strFreq?+?““?+?“0501“?+?“\r\n“;
????????????sp.Write(strTemp);
????????????sp.Close();
????????}
????????private?string?ChangeToWave1(int?i)
????????{
????????????double?dl?=?Convert.ToDouble(i?-?128);
????????????double?dltEMP?=?dl?/?256;
????????????double?dlTemp?=?(dltEMP?-?1)?*?256?+?1;
????????????string?str?=?Convert.ToInt32(dlTemp).ToString(“X4“);
????????????string?strWrite?=?str.Substring(str.Length?-?4?4);
????????????return?strWrite;
????????}
????????private?void?button3_Click(object?sender?EventArgs?e)
????????{
????????????if?(button3.Text==“開始錄音“)
????????????{
????????????????button3.Text?=?“停止錄音“;
????????????????//button3.Enabled?=?false;//停止使用按鈕
????????????????fs?=?new?FileStream(“f://123.txt“?
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-12-06?15:28??語音偵聽\
?????目錄???????????0??2014-12-06?15:28??語音偵聽\語音偵聽\
?????文件?????????186??2014-10-22?10:52??語音偵聽\語音偵聽\App.config
?????文件????????7176??2014-11-19?14:32??語音偵聽\語音偵聽\Form1.Designer.cs
?????文件????????5254??2014-11-19?14:31??語音偵聽\語音偵聽\Form1.cs
?????文件????????5817??2014-11-19?14:31??語音偵聽\語音偵聽\Form1.resx
?????文件????????3398??2014-11-17?11:13??語音偵聽\語音偵聽\Form2.Designer.cs
?????文件????????2118??2014-11-17?11:13??語音偵聽\語音偵聽\Form2.cs
?????文件????????5817??2014-11-17?11:13??語音偵聽\語音偵聽\Form2.resx
?????文件?????????514??2014-11-10?15:03??語音偵聽\語音偵聽\Program.cs
?????目錄???????????0??2014-12-06?15:28??語音偵聽\語音偵聽\Properties\
?????文件????????1356??2014-10-22?09:56??語音偵聽\語音偵聽\Properties\AssemblyInfo.cs
?????文件????????2876??2014-10-22?09:56??語音偵聽\語音偵聽\Properties\Resources.Designer.cs
?????文件????????5612??2014-10-22?09:56??語音偵聽\語音偵聽\Properties\Resources.resx
?????文件????????1099??2014-10-22?09:56??語音偵聽\語音偵聽\Properties\Settings.Designer.cs
?????文件?????????249??2014-10-22?09:56??語音偵聽\語音偵聽\Properties\Settings.settings
?????文件???????12963??2014-11-19?11:49??語音偵聽\語音偵聽\WavSC.cs
?????目錄???????????0??2014-12-06?15:28??語音偵聽\語音偵聽\bin\
?????目錄???????????0??2014-12-06?15:28??語音偵聽\語音偵聽\bin\Debug\
?????文件???????35328??2014-11-10?14:24??語音偵聽\語音偵聽\bin\Debug\SoundChat.dll
?????文件???????19456??2014-12-03?09:06??語音偵聽\語音偵聽\bin\Debug\語音偵聽.exe
?????文件?????????186??2014-10-22?10:52??語音偵聽\語音偵聽\bin\Debug\語音偵聽.exe.config
?????文件???????44544??2014-12-03?09:06??語音偵聽\語音偵聽\bin\Debug\語音偵聽.pdb
?????文件???????11600??2014-12-03?10:44??語音偵聽\語音偵聽\bin\Debug\語音偵聽.vshost.exe
?????文件?????????186??2014-10-22?10:52??語音偵聽\語音偵聽\bin\Debug\語音偵聽.vshost.exe.config
?????文件?????????490??2010-03-17?22:39??語音偵聽\語音偵聽\bin\Debug\語音偵聽.vshost.exe.manifest
?????目錄???????????0??2014-12-06?15:28??語音偵聽\語音偵聽\obj\
?????目錄???????????0??2014-12-06?15:28??語音偵聽\語音偵聽\obj\x86\
?????目錄???????????0??2014-12-06?15:28??語音偵聽\語音偵聽\obj\x86\Debug\
?????文件????????5359??2014-11-04?14:09??語音偵聽\語音偵聽\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
?????文件????????6718??2014-12-03?09:06??語音偵聽\語音偵聽\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
............此處省略12個文件信息
- 上一篇:wpf實現的手畫板
- 下一篇:C#微信帶參二維碼海報
評論
共有 條評論