• 大小: 4.57M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2024-04-29
  • 语言: C#
  • 标签: AI  采集  声音输入  

资源简介

采集麦克风输入并播放

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Oraycn.MPlayer;
using Oraycn.MCapture ;

namespace Oraycn.MPlayerDemo
{
    // 更多实用组件,请参见 www.oraycn.com

    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(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_F

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2020-07-30 17:46  Oraycn.MPlayerDemo\
     目录           0  2020-07-30 17:46  Oraycn.MPlayerDemo\.vs\
     目录           0  2020-07-30 17:46  Oraycn.MPlayerDemo\.vs\Oraycn.MPlayerDemo\
     目录           0  2020-07-30 17:46  Oraycn.MPlayerDemo\.vs\Oraycn.MPlayerDemo\v16\
     文件       53248  2019-12-23 11:56  Oraycn.MPlayerDemo\.vs\Oraycn.MPlayerDemo\v16\.suo
     目录           0  2020-07-30 17:46  Oraycn.MPlayerDemo\.vs\Oraycn.MPlayerDemo\v16\Server\
     目录           0  2020-07-30 17:46  Oraycn.MPlayerDemo\.vs\Oraycn.MPlayerDemo\v16\Server\sqlite3\
     文件           0  2019-12-23 11:56  Oraycn.MPlayerDemo\.vs\Oraycn.MPlayerDemo\v16\Server\sqlite3\db.lock
     文件      675840  2019-12-23 11:56  Oraycn.MPlayerDemo\.vs\Oraycn.MPlayerDemo\v16\Server\sqlite3\storage.ide
     目录           0  2020-07-30 17:46  Oraycn.MPlayerDemo\Dlls\
     文件      442880  2019-12-20 11:21  Oraycn.MPlayerDemo\Dlls\ESBasic.dll
     文件      237947  2019-12-20 11:21  Oraycn.MPlayerDemo\Dlls\ESBasic.xml
     文件     1226752  2020-06-01 09:03  Oraycn.MPlayerDemo\Dlls\Oraycn.MCapture.dll
     文件     1028808  2019-12-20 11:31  Oraycn.MPlayerDemo\Dlls\Oraycn.MCapture.xml
     文件     1137664  2020-06-22 09:04  Oraycn.MPlayerDemo\Dlls\Oraycn.MPlayer.dll
     文件     1075481  2019-12-20 11:33  Oraycn.MPlayerDemo\Dlls\Oraycn.MPlayer.xml
     文件        6550  2015-07-08 15:46  Oraycn.MPlayerDemo\Form1.Designer.cs
     文件        4334  2015-07-08 15:56  Oraycn.MPlayerDemo\Form1.cs
     文件        5817  2015-07-08 15:46  Oraycn.MPlayerDemo\Form1.resx
     文件        4124  2015-11-10 15:43  Oraycn.MPlayerDemo\Oraycn.MPlayerDemo.csproj
     文件        1557  2015-11-10 15:43  Oraycn.MPlayerDemo\Oraycn.MPlayerDemo.sln
     文件       28160  2020-09-17 14:54  Oraycn.MPlayerDemo\Oraycn.MPlayerDemo.suo
     文件         535  2015-07-08 15:56  Oraycn.MPlayerDemo\Program.cs
     目录           0  2020-07-30 17:46  Oraycn.MPlayerDemo\Properties\
     文件        1386  2015-07-07 16:56  Oraycn.MPlayerDemo\Properties\AssemblyInfo.cs
     文件        2876  2015-11-10 11:24  Oraycn.MPlayerDemo\Properties\Resources.Designer.cs
     文件        5612  2015-07-06 11:28  Oraycn.MPlayerDemo\Properties\Resources.resx
     文件        1118  2015-11-10 11:24  Oraycn.MPlayerDemo\Properties\Settings.Designer.cs
     文件         249  2015-07-06 11:28  Oraycn.MPlayerDemo\Properties\Settings.settings
     文件         144  2015-11-10 11:24  Oraycn.MPlayerDemo\app.config
     目录           0  2020-07-30 17:46  Oraycn.MPlayerDemo\bin\
............此处省略41个文件信息

评论

共有 条评论