1. 程式人生 > >麥克風採集與播放 (原始碼)

麥克風採集與播放 (原始碼)

    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; } }

相關推薦

麥克風採集播放 原始碼

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

V4L2視訊採集H.264編碼原始碼大放送:Linux視訊採集編碼

這幾天的努力也算沒有白費,現在我將貢獻出我的成果,當然程式碼很大一部分都不是我寫的。 V4L2視訊採集我參考了V4L2官方原始碼,H.264編碼我使用了開源編碼庫x264,並參考了網上的一些例子。 但

Android音訊實時傳輸播放

服務端共開放兩個埠,一個udp上行埠用來接收amr音訊流,另一個tcp下行埠用來發送amr音訊流。 我這裡寫的服務端實現了組播的功能,即一個人在錄音,可以同時讓很多人同時聽到。 簡而言之,服務端做的唯一一件事情就是轉發音訊流,囧rz。。。 在這裡,我只貼出一部分程式碼,後

Android音訊實時傳輸播放:AMR硬編碼硬解碼

轉載請註明出處! 在Android中我所知道的音訊編解碼有兩種方式: (一)使用AudioRecord採集音訊,用這種方式採集的是未經壓縮的音訊流;用AudioTrack播放實時音訊流。用這兩個類的話,如果需要對音訊進行編解碼,就需要自己移植編解碼庫了,比如可以移植il

Android音訊實時傳輸播放:服務端

我偷懶就用java寫了個簡單的伺服器,大家明白原理就好。 服務端共開放兩個埠,一個udp上行埠用來接收amr音訊流,另一個tcp下行埠用來發送amr音訊流。 我這裡寫的服務端實現了組播的功能,即一個人在錄音,可以同時讓很多人同時聽到。 簡而言之,服務端做的唯一一件

自動升級系統的設計實現原始碼

  對於PC桌面應用程式而言,自動升級功能往往是必不可少的。而自動升級可以作為一個獨立的C/S系統來開發,這樣,就可以在不同的桌面應用中進行復用。基於的檔案傳送功能,我實現了一個可直接複用的自動升級系統OAUS,現在將其分享給大家。這篇文章將著重介紹OAUS的相關背景、使用方法,至於詳細的實現細節,大家可

Android 錄音MediaRecorder播放MediaPlayer

通過MediaRecorder和MediaPlayer實現聲音的錄製和播放,程式碼比較簡單,直接貼程式碼。xml檔案裡面只有四個按鈕就不貼了。 UI 程式碼: VoiceActivity.class package com.zy.ione; import com.zy

手機影音第十四天,本地音樂列表的展示播放利用視頻播放的布局

獲取本地音樂 共用視頻播放頁面來播放音樂 代碼已經托管到碼雲,有興趣的小夥伴可以下載看看 https://git.oschina.net/joy_yuan/MobilePlayer 效果圖: Android系統提供了MediaScanner,MediaProvider,MediaS

redis原始碼分析思考十三——字串型別的命令實現(t_string.c)

    在對字串操作的命令中,主要有增加刪查該、批處理操作以及編碼的轉換命令,現在列出對字串物件操作的主要常用命令: 常用命令表 命令 對應操作 時間複雜度

ItemDecoration深入解析實戰——原始碼分析

一 概述 ItemDecoration 是 RecyclerView 中的一個抽象靜態內部類。 An ItemDecoration allows the application to add a special drawing and layout offset to specific item v

redis原始碼分析思考——字典中鍵的兩種hash演算法

      在Redis字典中,得到鍵的hash值顯得尤為重要,因為這個不僅關乎到是否字典能做到負載均衡,以及在效能上優勢是否突出,一個良好的hash演算法在此時就能發揮出巨大的作用。而一個良好的has

redis原始碼分析思考——物件

    談及物件,我們不免會立即聯想到Java、C++等面向物件的語言,而在C中是沒有物件這一說法的,為了方便管理與程式碼整體的優化,redis基於前面幾篇部落格的資料結構自建了一套物件系統。這個系統包含著字串物件、列表物件、雜湊物件、集合物件以及有序集合物件。

看透SpringMVC原始碼分析實踐

一、網站架構及其演變過程   1.軟體的三大型別          軟體分為三個型別:單機軟體、BS結構的軟體(瀏覽器-服務端)、CS結構的軟體(客戶端-服務端)。 2.BS的基礎結構     &nb

看透SpringMVC原始碼分析實踐

一、Tomcat的頂層結構及啟動過程 1.Tomcat的頂層結構        Tomcat中最頂層的容器叫Server,代表整個伺服器,Server至少包含一個Service用於具體的服務。Service主要包含兩部分,Connector和Conta

halcon影象採集之同步synchronous非同步asynchronous

通常情況下,當我們抓取幀的時候是從一個連續的視訊流序列中去抓取一個或者多個視訊幀。儘管近來有許多的專業裝置使用數字訊號,但大多數情況下,視訊訊號是模擬訊號(analog)。最常見的模擬視訊格式是

Android多媒體之認識MP3內建媒體播放MediaPlayer

零、前言 作為90後,mp3格式的音樂可謂靈魂之友。 小時候帶著耳機,躺在桌子上聽歌看月亮心情依稀。 當某個旋律想起,還會不會浮現某個風景,某個人……, 今天全程單曲播放——梁靜茹-勇氣(獻上頻譜) 主要任務:SD卡音樂、網路音訊流的播放及控制 MP3的

阿里雲播放器SDK的正確開啟方式 | 功能、架構應用

阿里雲播放器SDK(ApsaraVideo for Player SDK)是阿里視訊雲端到雲到端服務的重要一環,除了支援點播和直播的基礎播放功能外,還深度融合視訊雲業務,支援視訊的加密播放、安全下載、首屏秒開、低延時等業務場景,為使用者提供簡單、快速、安全、穩定的視訊播放

Spring IOC原理原始碼解析(@Autowired原理詳解 :標識屬性方法)

原始碼推薦看這篇部落格的時候開啟Spring原始碼,一邊看原始碼,一邊看部落格上程式碼的關鍵處的註釋,這樣能更好的理解Spring IOC的流程及內部實現和使用方法。如果你對IOC的原理有些瞭解,則這些註釋能幫你更深入的理解其實現方式。 Spring容器在每個

Nginx原始碼分析實踐---編寫一個簡單的Http模組

在上一節中,我們通過修改配置檔案,便能讓nginx去訪問我們寫的html檔案,並返回給瀏覽器。問題是:nginx是如何檢測到我們寫的配置項的?檢測到後,nginx又是如何知道該進行什麼操作的? 本節通過親自實踐,寫一個經典的Hello World模組來了解相應的流程是如何進行的。我們採用自上

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

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