Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 软件时空 > 软件相关 > 将声音存入sql server数据库并播放
【标  题】:将声音存入sql server数据库并播放
【关键字】:sql,server
【来  源】:http://blog.chinaunix.net/article.php?articleId=37872&blogId=117

将声音存入sql server数据库并播放

Your Ad Here

wav格式说明:44字节

RIFF(4)+大小(4)+WAVE(4)+fmt (4)+ChunkSize(4)+wFormatTag(2)+nChannels(2)+nSamplesPerSec(4)+nAvgBytesPerSec(4)+nBlockAlign(2)

+wBitesPerSample(2)+data(4)+datasize(4)

using System.Runtime.InteropServices;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using System.IO;
using System;

class test
{
 [DllImport("winmm.dll")]
 extern static long sndPlaySound(string filename, long flags);
 public static void myPlaySound(byte[] wave)
 {
  string wavFile = "temp.wav";
  FileStream fs = new FileStream(wavFile,FileMode.Create);
  fs.Write(wave,0,wave.Length);
  fs.Close();
  sndPlaySound(wavFile,0);
 }
 public static void myPlaySound(Stream wavStream)
 {
  string wavFile = "temp.wav";
  byte[] wave = new byte[wavStream.Length];
  wavStream.Read(wave,0,wave.Length);
  FileStream fs = new FileStream(wavFile,FileMode.Create);
  fs.Write(wave,0,wave.Length);
  fs.Close();
  sndPlaySound(wavFile,0);
 }
 
 
 public static void Main(string[] args)
 {

  #region 写入数据库
  //  string srcFile = @"D:\project\TTS\TTS\MKCEVOICE\wish.wav";
  //  FileStream fs = new FileStream(srcFile,FileMode.Open,FileAccess.Read);
  //  byte[] byteVoice = new byte[fs.Length];
  //  fs.Read(byteVoice,0,byteVoice.Length);
  //  
  SqlConnection sqlConn = new SqlConnection("Data Source=(local);user=sa;password=***;Initial Catalog=roren");
  SqlDataAdapter sqlDa = new SqlDataAdapter("select * from voice",sqlConn);
  //  SqlCommandBuilder sqlCb =new SqlCommandBuilder(sqlDa);
  DataSet sqlDs = new DataSet();
  sqlDa.Fill(sqlDs);
  //
  //  DataRow dr = sqlDs.Tables[0].NewRow();
  //  dr[0] = "wish";
  //  dr[1] = byteVoice;
  //  sqlDs.Tables[0].Rows.Add(dr);
  //  sqlDa.Update(sqlDs);
  //  fs.Close();
  #endregion
  
  foreach(DataRow dr in sqlDs.Tables[0].Rows)
  {
   Console.WriteLine(dr["word"]);
   myPlaySound((byte[])dr["voice"]);
  }
  
  Console.WriteLine("Game Over!");
  Console.ReadLine();
 }
}

JavaMail的初步实现:【上一篇】
lint翻译为"长整数" --<<C专家编程>>中一个老鼠坏锅汤的一句话:【下一篇】
【相关文章】
  • Constructing a WebServers with Pattern
  • Sqlite3.2.5 编译错误 "Tcl_WideInt undeclared"
  • Vmware 4 下Sco OpenServer 5.0.5完全安装手册
  • WebLogic Server 管理最佳实践
  • Instant Rails: Ruby, Rails, Apache, and MySQL pack
  • 让Sqlite3以GB2312编码存储汉字
  • 自由软件还是Windows Server?
  • SQL语句基本的用法
  • WebSphere Application Server DataSource Connect
  • 在AIX下安装WebLogic Server
  • 【随机文章】
  • linux控制台下的svgalib绘图
  • Photoshop 7.0 风格化滤镜(2)
  • linux显卡的配置
  • 用tnl实现高可信赖的对象同步机制
  • NFS简介
  • Web控件与数据源的系结(Data Binding)--数据系结叙述
  • sco openserver 6.0(更新版) 在hp ML150G3(SATA硬盘) 上安装注意事
  • 面向对象设计过程3:细化问题定义
  • 光纤与六类:谁离你的目标近
  • CorelDRAW 12循序渐进(9)-对象的群组与造型
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.