1. 程式人生 > >C#麥克風錄音元件與播放原始碼

C#麥克風錄音元件與播放原始碼

複製程式碼
    public partial class Form1 : Form
    {
        private IAudioPlayer audioPlayer;
        private IMicrophoneCapturer microphoneCapturer;

        public Form1()
        {
            InitializeComponent();
        }

        private void button_mic_Click(object sender, EventArgs e)
        {
            
try { this.microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(int.Parse(this.textBox_mic.Text)); this.microphoneCapturer.AudioCaptured += new ESBasic.CbGeneric<byte[]>(microphoneCapturer_AudioCaptured); this.audioPlayer = PlayerFactory
.CreateAudioPlayer(int.Parse(this.textBox_speaker.Text), 16000, 1, 16, 2); this.microphoneCapturer.Start(); this.label_msg.Text = "正在採集麥克風,並播放 . . ."; this.label_msg.Visible = true; this.button_wav.Enabled = false; this.button_mic.Enabled = false
; this.button_stop.Enabled = true; } catch (Exception ee) { MessageBox.Show(ee.Message); } } void microphoneCapturer_AudioCaptured(byte[] audioData) { if (this.audioPlayer != null) { this.audioPlayer.Play(audioData); } } private void button_wav_Click(object sender, EventArgs e) { try { string path = ESBasic.Helpers.FileHelper.GetFileToOpen2("請選擇要播放的wav檔案", AppDomain.CurrentDomain.BaseDirectory, ".wav"); if (path == null) { return; } AudioInformation info = PlayerFactory.ParseWaveFile(path); if (info.FormatTag != (int)WaveFormats.Pcm) { MessageBox.Show("僅僅支援PCM編碼方式的語音資料!"); return; } int secs = info.GetTimeInMsecs() / 1000; //聲音資料的播放時長 this.audioPlayer = PlayerFactory.CreateAudioPlayer(int.Parse(this.textBox_speaker.Text), info.SampleRate, info.ChannelCount, info.BitsNumber, secs + 1); this.audioPlayer.Play(info.AudioData); this.label_msg.Text = "正在播放wav檔案 . . ."; this.label_msg.Visible = true; this.button_wav.Enabled = false; this.button_mic.Enabled = false; this.button_stop.Enabled = true; } catch (Exception ee) { MessageBox.Show(ee.Message); } } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { if (this.microphoneCapturer != null) { this.microphoneCapturer.Stop(); this.microphoneCapturer.Dispose(); this.microphoneCapturer = null; } if (this.audioPlayer != null) { this.audioPlayer.Dispose(); this.audioPlayer = null; } } private void button_stop_Click(object sender, EventArgs e) { if (this.audioPlayer == null) { return; } if (this.microphoneCapturer != null) { this.microphoneCapturer.Stop(); this.microphoneCapturer.Dispose(); this.microphoneCapturer = null; } this.audioPlayer.Clear(); this.audioPlayer.Dispose(); this.audioPlayer = null; this.label_msg.Visible = false; this.button_wav.Enabled = true; this.button_mic.Enabled = true; this.button_stop.Enabled = false; } }
複製程式碼

相關推薦

C#麥克風錄音元件播放原始碼

public partial class Form1 : Form { private IAudioPlayer audioPlayer; private IMicrophoneCapturer microphoneCapturer; publ

C# DataGridView控制元件ListView控制元件的對比學習(二):ListView控制元件學習

一、定義:     表示Windows列表檢視控制元件,一般用來呈現資料,是一種輕量級的呈現資料的方法。 二、重要的屬性:     1、第一個非常重要的屬性是View:獲取或設定項在控制元件中的顯示方式,包括Details、LargeIcon、List、SmallI

麥克風採集播放原始碼

public partial class Form1 : Form { private IAudioPlayer audioPlayer; private IMicrophoneCapturer microphoneCapturer;

【Tomcat9原始碼分析】元件框架概述

1 元件與框架介紹 Server:代表整個Catalina Servlet容器,可以包含一個或多個Service Service:包含Connector和Container的集合,Service用適當的Connector接收使用者的請求,

音訊的錄製播放元件SYAudio

音訊的錄製 錄製後會進行壓縮更小的檔案,並以mp3格式輸出 錄製過程中,可以監測音量的變化 可以設定錄音時間長 音訊的播放 本地的檔案播放 網路檔案播放 播放狀態監測 播放時間監測 檔案播放總時間 當前播放進度時間 效果圖 使用注意:

【鐵匠Smith先生的專欄】關注Linux系統軟體開發、多媒體圖形技術、Linux OS技術、多程序多執行緒併發網路程式設計、架構模式研究實踐、AI等新技術動向、C/C++最新程式設計技術、開原始碼整合應用等

關注Linux系統軟體開發、多媒體圖形技術、Linux OS技術、多程序多執行緒併發網路程式設計、架構模式研究與實踐、AI等新技術動向、C/C++最新程式設計技術、開原始碼整合與應用等...

C++ STL 記憶體配置的設計思想關鍵原始碼分析

下面會結合關鍵原始碼分析C++STL(SGI版本)的記憶體配置器設計思想。關鍵詞既然是“思想”,所以重點也就呼之欲出了。 1、allocator的簡短介紹 我閱讀的原始碼是SGI公司的版本,也是看起來最清楚的版本,各種命名最容易讓人看懂。allocator有人叫它空間配置器,因為空間不一定是記憶體,也可以是

C++STL記憶體配置的設計思想關鍵原始碼分析

說明:我認為要讀懂STL中allocator部分的原始碼,並汲取它的思想,至少以下幾點知識你要了解:operator new和operator delete、handler函式以及一點模板知識。否則,下面你很可能看不大明白,補充點知識再學習STL原始碼比較好。 下面會結合關鍵原始碼分析C++STL(SGI版

[原始碼和文件分享]基於java的C語言試題生成考試系統

摘 要 當前,網路教學方興未艾。網上考試已在其中扮演了重要的角色,傳統試卷考試方式有待提高。網路教學已從其規範性、科學性及考試工作組織、管理的統一性,影響到教學質量的好壞。基於此,本系統開發實現了基於B/S模式的c試題生成與考試系統,其中資料庫採用MYSQL,開發平臺是jsp,開發工具是ecli

Android多媒體之認識聲音、錄音播放(PCM)

一、對聲音的簡單認識 1、模擬訊號[摘錄於此] 模擬訊號傳輸過程中就是利用感測器把各種自然界各種連續的訊號轉換為幾乎一模一樣的電訊號。 比如說話聲音,原本是聲帶的震動。經過麥克風的採集,將聲波訊號轉換為電訊號, 電訊號波形是和原來的聲波波形一樣的。只是換種物理量來表示和傳遞。(電訊號模擬振動訊號)。 複製

一個簡單的用ASP.NET/C#開發的元件化Web應用程式(附原始碼

==============================================================================1)建立一個類來處理使用者登入,將該類編譯成一個裝配件(assembly),併發布到站點的bin目錄下。========

C#通過webbrowser控制元件javascript互動

1.C#裡呼叫控制元件裡面網頁的js函式     //呼叫JavaScript的messageBox方法,並傳入引數     object[] objects = new object[1];     objects[0] = “C#訪問JavaScript指令碼";  

呼叫麥克風錄音播放

匯入AVFoundation.framework 引入#import <AVFoundation/AVFoundation.h> //定義屬性 { //錄音器 AVAudioRecorder *recorder; //播放器 AV

【應用CC語言實現行列式矩陣的運算系統(+原始碼

文章目錄 01 - 行列式和矩陣 1.1 - 行列式定義 1.2 - 矩陣定義 02 - 基本運算 2.1 - 行列式基本運算 2.2 - 矩陣基本運算

輕量級C#網路通訊元件StriveEngine —— C/S通訊開源demo(附原始碼

private ITcpServerEngine tcpServerEngine; private void button1_Click(object sender, EventArgs e) { try { //初

半透明視窗中顯示標準控制元件(控制元件文字不透明)的實現方案(附原始碼

原文 http://blog.csdn.net/harbinzju/article/details/7907127 和大家分享一下在半透明視窗中顯示標準控制元件的實現方案。通過層疊視窗可以簡單實現半透明與不規則形狀視窗的效果,但在其上顯示標準控制元件(控制元件與文字不

C# 多執行緒跨執行緒訪問介面控制元件

在編寫WinForm訪問WebService時,常會遇到因為網路延遲造成介面卡死的現象。啟用新執行緒去訪問WebService是一個可行的方法。 典型的,有下面的啟動新執行緒示例: private void LoadRemoteAppVersion()

android 呼叫系統自帶錄音實現,語音錄製播放

相關許可權:<uses-permission android:name="android.permission.RECORD_AUDIO"></uses-permission> <uses-permission android:name="and

Unity3d-c# Socket非同步通訊Unity元件資料更新的處理

首先基於C#的Socket的BeginReceive非同步接收和BeginSend非同步傳送資料的底層的實現也是多執行緒處理,當然也可以自己用執行緒來實現;C#的非同步Socket簡單的例子和教程網上很多,在此就不再累贅了;結合剛開始說的,C#的非同步Socket實際是多執

C# WPF TextBox控制元件變數的繫結

在WPF中,可以將TextBox控制元件(其他控制元件也基本一樣)與相應的變數進行繫結,做出改變變數則控制元件也跟著改變的效果。雖然其原理跟原本的訊息響應是一樣的,只是在外部加了層封裝,但就是因為這層封裝,使得在編寫介面的過程中方便了很多。 首先需要宣告一個類