none
Extracting audio from the database

    Question

  • I created a web service to retrieve the audio streams from my logs database. 
    For testing, I have included code to write the bytes to a file. 
    The problem is, the resulting file is not an audio file. 

    Should I be doing some conversion of the byte encoding?


    public byte[] GetSoundFile(int FileID)

    {

    byte[] ByteArray = null ;

    try

    {

    using (SqlConnection SqlConn = new SqlConnection(@"Server=(local);User ID=dev;password=dev;Database=Logs"))

    {

    SqlCommand SqlComm = new SqlCommand(String.Format("SELECT Data FROM EngineRecoAudioData WHERE SpeechRequestID={0}", FileID), SqlConn);

    SqlConn.Open();

    object TempObject = SqlComm.ExecuteScalar();

    SqlConn.Close();

    if (TempObject != null)

    {

    ByteArray = (byte[])TempObject;

    }

    using (System.IO.FileStream fs = new System.IO.FileStream("d:\\temp\\fromMSS.wav", System.IO.FileMode.Create))

    {

    fs.Write(ByteArray, 0, ByteArray.Length);

    fs.Close();

    }

    }

    }

    catch (Exception ex)

    {

    ByteArray = System.Text.UnicodeEncoding.Unicode.GetBytes(ex.Message.ToCharArray(), 0, ex.Message.Length);

    }

    return ByteArray;

    }

     


    lundi 7 avril 2008 14:09

Toutes les réponses