写个叫号的小demo

长相如下

代码如下

 using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using NAudio.Wave; namespace VoiceDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
} private void button1_Click(object sender, EventArgs e)
{
string[] lstMp3s = Directory.GetFiles(Application.StartupPath + "\\mp3", "*.mp3");
Dictionary<string, string> lstDicMp3 = new Dictionary<string, string>();
for (int i = ; i < lstMp3s.Length; i++)
{
lstDicMp3.Add(Path.GetFileNameWithoutExtension(lstMp3s[i]), lstMp3s[i]);
}
lstDicMp3 = lstDicMp3.OrderByDescending(p => p.Key.Length).ToDictionary(p => p.Key, o => o.Value); string strText = textBox1.Text;
List<string> lst = new List<string>();
GetPlayList(lstDicMp3, strText, ref lst);
foreach (var item in lst)
{
using (var ms = File.OpenRead(lstDicMp3[item]))
using (var rdr = new Mp3FileReader(ms))
using (var wavStream = WaveFormatConversionStream.CreatePcmStream(rdr))
using (var baStream = new BlockAlignReductionStream(wavStream))
using (var waveOut = new WaveOut(WaveCallbackInfo.FunctionCallback()))
{
waveOut.Init(baStream);
waveOut.Play();
while (waveOut.PlaybackState == PlaybackState.Playing)
{
Thread.Sleep();
}
}
}
} private void GetPlayList(Dictionary<string, string> lstDicMp3, string strText, ref List<string> lst)
{
foreach (var item in lstDicMp3)
{
if (strText.StartsWith(item.Key))
{
lst.Add(item.Key);
strText = strText.Remove(, item.Key.Length);
break;
}
}
if (strText.Length > )
GetPlayList(lstDicMp3, strText, ref lst);
}
}
}

demo地址

https://pan.baidu.com/s/1eSiy98m

最新文章

  1. url中的特殊字符问题
  2. js自定义弹出框
  3. 让ZenCoding提升编码速度
  4. jquery 找不到live方法解决
  5. Python 学习笔记1
  6. HTML上传文件写法
  7. jar包和war包的区别
  8. 重构实践——为了try-catch大兴排场
  9. [记录]使用openGL显示点云的一个程序
  10. modelsim使用命令
  11. pod install后出现: [!] `&lt;PBXResourcesBuildPhase UUID=`xxxx`&gt;` attempted to initialize an object with an unknown UUID
  12. org.springframework.core.Ordered接口
  13. VoiceEngine获取硬件信息
  14. python学习日记(数据结构习题)
  15. 算法:60.第k个排列
  16. SharePoint 2013 APP 开发示例 (一)List 读写
  17. 译 5. Spring使用JDBC访问关系数据
  18. [UE4]小地图接口设计
  19. OCR技术浅探(转)
  20. MFC载入BMP图片

热门文章

  1. 生成动态Lambda表达式1
  2. Android中TabHost中实现标签的滚动以及一些TabHost开发的奇怪问题
  3. 仿照Android的池化技术
  4. 为 Mac Finder 增加右键文件打包压缩(免费)
  5. LaTeX —— 特殊符号与数学字体
  6. String方法总结
  7. zlib minizip 实现解压zip
  8. dos命令查看端口状态
  9. Poco logger 日志使用小析
  10. JScript运行批处理命令的做法