语音存储在C#下的表中 [英] voice storing in table under c#

查看:58
本文介绍了语音存储在C#下的表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个从数据库检索语音的应用程序,并且有一列存储语音的内容,我选择了数据类型(varbinary(max)),但是我不知道值的形式应该我输入以填充表格.

这将是录制声音的路径吗?

I develop an app that retrieve voice from data base and there is a column to store voices in it and I select the data type (varbinary (max)), but I don''t know the form of value should I enter to fill the tabel.

It will be a path of the recorded sound? or what?

推荐答案

可能是-但也可能是语音数据本身.根据您的数据库总大小,将实际声音存储在数据库中可能是有意义的-这样,数据是否存在-如果存储路径,则删除该文件所指向的文件可能不存在,或不包含在同一备份中,等等.

就个人而言,如果可能的话,我宁愿将我的数据放在一个地方.它还有助于防止旧的两个具有相同名称的项目的问题!


我想建立表并想要存储语音,然后我将在If语句中使用该语音,这取决于If语句,我的主要问题是我应如何填充该语音的值,例如:>我的专栏名称是"voices"
而且我有MP3file想要将其存储在TABEL中怎么办?"




将文件读取为字节数组:
It could be - but it also could be the voice data itself. Depending on your total DB size, it can make sense to store the actual voice inside the database - that way the data is either there or not - if you store a path, the file it points to may not be there if the file is deleted, or not included in the same backup, or whatever.

Personally, if at all possible, I prefer to keep my data together in one place. It also helps to prevent the old two-different-items-with-the-same-name problem!


"I want to build table and I want to store a voice, then I will use this voice in my application depending on If statement my major problem is what should I fill the value of that voice>>> ex:my column name is "voices"
and I have MP3file want to store it in the TABEL how I can do that?"




Read your file into an array of bytes:
byte[] bytes = File.ReadAllBytes(@"D:\Temp\MyVoiceFile.mp3");


或从流中获取它:


Or fetch it from the stream:

byte[] bytes = myStream.GetBuffer();

然后仅需使用参数化的INSERT语句即可:

Then just use a parametrized INSERT statement:

using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("INSERT INTO myTable (voices) VALUES (@MP3)", con))
        {
        com.Parameters.AddWithValue("@MP3", bytes);
        com.ExecuteNonQuery();
        }
    }


这篇关于语音存储在C#下的表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆