基本信息
源码名称:C# 录制语音 保存成mp3格式 并播放
源码大小:8.83M
文件格式:.zip
开发语言:C#
更新时间:2016-04-09
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
public partial class AudioMsgForm : Form
{
private int fileIndex;
private AudioFileMaker audioFileMaker = new AudioFileMaker();
private IAudioPlayer audioPlayer;
private IMicrophoneCapturer microphoneCapturer = CapturerFactory.CreateMicrophoneCapturer(0);
private Byte[] audioData = new byte[0];
public string StorePath
{
get
{
return String.Format("语音备忘\\AudioMsg{0}.ad", this.fileIndex);
}
}
public AudioMsgForm()
{
InitializeComponent();
this.microphoneCapturer.AudioCaptured = new ESBasic.CbGeneric<byte[]>(microphoneCapturer_AudioCaptured);
this.audioPlayer = PlayerFactory.CreateAudioPlayer(0, this.microphoneCapturer.SampleRate, this.microphoneCapturer.ChannelCount);
if(!Directory.Exists("语音备忘"))
{
Directory.CreateDirectory("语音备忘");
}
string[] fileName = Directory.GetFiles("语音备忘");
foreach (string name in fileName)
{
this.fileIndex ;
}
}
void microphoneCapturer_AudioCaptured(byte[] data)
{
this.audioData = BufferJointer.Joint(this.audioData, data);
this.decibelDisplayer1.DisplayAudioData(data);
}
private void button_start_Click(object sender, EventArgs e)
{
this.microphoneCapturer.Start();
this.label_notify.Text = "正在录音!";
this.label_notify.ForeColor = Color.Red;
this.button_start.Enabled = false;
this.button_stop.Enabled = true;
}
private void button_stop_Click(object sender, EventArgs e)
{
this.microphoneCapturer.Stop();
File.WriteAllBytes(this.StorePath, this.audioData);
this.label_notify.Text = "录音完成!";
this.label_notify.ForeColor = Color.Blue;
this.LoadAduioFileList();
this.button_start.Enabled = true;
this.button_stop.Enabled = false;
this.fileIndex ;
return;
}
private void toolStripButton1_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(this.toolStripComboBox1.SelectedText))
{
MessageBox.Show("请选择列表中的一项!");
this.toolStripComboBox1.DroppedDown = true;
return;
}
this.audioPlayer.Play(File.ReadAllBytes("语音备忘\\" this.toolStripComboBox1.SelectedText));
}
private void AudioMsgForm_Shown(object sender, EventArgs e)
{
this.LoadAduioFileList();
this.button_stop.Enabled = false;
}
private void LoadAduioFileList()
{
this.toolStripComboBox1.Items.Clear();
string[] fileName = Directory.GetFiles("语音备忘");
foreach (string name in fileName)
{
string shortName = name.Substring(name.LastIndexOf("\\") 1, name.Length - 1 - name.LastIndexOf("\\"));
this.toolStripComboBox1.Items.Add(shortName);
}
}
private void toolStripButton2_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(this.toolStripComboBox1.SelectedText))
{
MessageBox.Show("请选择列表中的一项!");
this.toolStripComboBox1.DroppedDown = true;
return;
}
if (!Directory.Exists("mp3目录"))
{
Directory.CreateDirectory("mp3目录");
}
string path= String.Format("mp3目录\\{0}.mp3", Path.GetFileNameWithoutExtension(this.toolStripComboBox1.SelectedText));
this.audioFileMaker.Initialize(path, this.microphoneCapturer.SampleRate, this.microphoneCapturer.ChannelCount);
this.audioFileMaker.AddAudioFrame(File.ReadAllBytes("语音备忘\\" this.toolStripComboBox1.SelectedText));
this.audioFileMaker.Close(true);
DialogResult dialogResult = MessageBox.Show("转存成功,是否打开目录查看?", "提醒", MessageBoxButtons.YesNo);
if (dialogResult == System.Windows.Forms.DialogResult.Yes)
{
Process.Start("explorer.exe", "mp3目录");
}
}
}