客服小妹是如何泡到手的——C#定时提醒·语音录制·语音播放·文件转录Demo源码——倾情奉献!

时间:2020-11-29 05:46:04

一.需求提出

客服小妹跟我说,每天要统计新加好友数,得先记下昨天的数目,然后查看今天的数目,还要相减,打字,记录——好麻烦!

又说,客户多的时候,忙起这头忘了那头,文字记录备忘又太费劲!

我说,赐你一个软件!于是有了下面这个东西。

二.主要界面

客服小妹是如何泡到手的——C#定时提醒·语音录制·语音播放·文件转录Demo源码——倾情奉献!      客服小妹是如何泡到手的——C#定时提醒·语音录制·语音播放·文件转录Demo源码——倾情奉献!

三.主要功能简介

1 .可定时弹出主界面,输入今日好友数,计算出新加好友数,并将今日好友数存盘。

2.统计信息显示在界面上,并且写入word文件中以备查看,并自动拷贝至剪切板,方便复制。

3.可语音备忘,录制语音消息,并保存在文件夹中。

4.可下拉列表查看文件,并选中播放。

5.可将原始文件转录成MP3文件。

四.编码实现

1.好友统计功能相关实现

先设计两个属性,直接对应于两个文件,这样一来,既能以字段的风格来操作文件,又能将变量持久化到硬盘上,以保存状态。

        public int TodayFriendsCount
        {
            get
            {
                if (!File.Exists("todayFriendsCount.dat"))
                {
                    File.WriteAllBytes());
                }
                );
            }
            set { File.WriteAllBytes("todayFriendsCount.dat", BitConverter.GetBytes(value)); }
        }

        public bool IsHandled
        {
            get
            {
                if (!File.Exists("HandledSign.dat"))
                {
                    File.WriteAllBytes("HandledSign.dat", BitConverter.GetBytes(false));
                }
                );
            }
            set
            {
                File.WriteAllBytes("HandledSign.dat", BitConverter.GetBytes(value));
                this.toolStripLabel_isHandled.Text = this.IsHandled ? "今日已处理" : "今日未处理";
                this.toolStripLabel_isHandled.ForeColor = this.IsHandled ? Color.Red : Color.Blue;
            }
        }

计算按钮事件处理方法

        private void button1_Click(object sender, EventArgs e)
        {
            //已经处理过
            if (this.IsHandled)
            {
                DialogResult dialogResult = MessageBox.Show("今日已经执行过,是否还要继续操作?", "提醒", MessageBoxButtons.YesNo);
                if (dialogResult == DialogResult.No)
                {
                    this.ReFocusInput();
                    return;
                }
            }

            if (String.IsNullOrEmpty(this.textBox_todayCount.Text.Trim()))
            {
                MessageBox.Show("输入不能为空!");
                this.textBox_todayCount.Focus();
                return;
            }          

            int todayFriendsCountNew = int.Parse(this.textBox_todayCount.Text.Trim());
            int incremeFriendsCount = todayFriendsCountNew - this.TodayFriendsCount;
            this.richTextBox_ShowNewCount.Text = string.Format("今日新加好友:{0} - {1} = {2}",
                                                                todayFriendsCountNew,
                                                                this.TodayFriendsCount,
                                                                incremeFriendsCount);
            Clipboard.SetText(this.richTextBox_ShowNewCount.Text);          

            string text = string.Format("{0}   {1}\r\n", DateTime.Now.ToShortDateString(), this.richTextBox_ShowNewCount.Text);
            this.AppendFriendsDiary(text);

            //重置基础参数
            this.ReSetInitialParameter(todayFriendsCountNew, true);
            //重聚焦输入框
            this.ReFocusInput();
        }

2.语音备忘功能相关实现

设计一个byte数组用于存放语音数据

 ];

采集发生时,将声音数据数组拼接到字段数组上。

        void microphoneCapturer_AudioCaptured(byte[] data)
        {
            this.audioData = BufferJointer.Joint(this.audioData, data);
            this.decibelDisplayer1.DisplayAudioData(data);
        }

停止录制时写入文件

        private void button_stop_Click(object sender, EventArgs e)
        {
            this.microphoneCapturer.Stop();//停止采集
            this.originalFileManager.WriteFile(this.audioData);//写文件
            this.LoadAduioFileList();
            this.ShowWorkStatus(false);
        }

播放选中文件

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            if (this.ExamineSelectNull())
            {
                return;
            }
            this.audioPlayer.Play(this.originalFileManager.ReadFile(this.toolStripComboBox1.SelectedText));
        }

转录为MP3文件

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            if (this.ExamineSelectNull())
            {
                return;
            }

            this.MakeAudioFile();

            DialogResult dialogResult = MessageBox.Show("转存成功,是否打开目录查看?", "提醒", MessageBoxButtons.YesNo);
            if (dialogResult == System.Windows.Forms.DialogResult.Yes)
            {
                this.mP3FileManager.OpenDirectory();
            }
        }

五.源码下载

下载: 客服备忘系统(包含语音备忘功能、语音播放功能、并能将语音文件转录成MP3)