Click here to Skip to main content
15,904,638 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Dear Friends,


I hope all are doing well. I need one help, How to convert audio file to text in c#.
Posted
Updated 24-Mar-23 16:23pm

 
Share this answer
 
Comments
[no name] 9-Dec-15 1:42am    
Dear Mehdi Gholam,

First Thank you so much. I tried it read only .wav formats. It will read all format audio files ?
 
Share this answer
 
Comments
[no name] 9-Dec-15 2:14am    
Dear DanielBrownAU,

First Thank you so much. I tried it read only .wav formats. It will read all format audio files ?
DanielBrownAU 9-Dec-15 17:01pm    
I beleive so yes, but its been awhile since I used thoese API's
C#
SpeechRecognitionEngine sre = new SpeechRecognitionEngine();
Grammar gr = new DictationGrammar();
sre.LoadGrammar(gr);
sre.SetInputToWaveFile("C:\\Users\\Soham Dasgupta\\Downloads\\Podcasts\\Engadget_Podcast_353.wav");
sre.BabbleTimeout = new TimeSpan(Int32.MaxValue);
sre.InitialSilenceTimeout = new TimeSpan(Int32.MaxValue);
sre.EndSilenceTimeout = new TimeSpan(100000000);
sre.EndSilenceTimeoutAmbiguous = new TimeSpan(100000000); 

StringBuilder sb = new StringBuilder();
while (true)
{
    try
    {
        var recText = sre.Recognize();
        if (recText == null)
        {               
            break;
        }

        sb.Append(recText.Text);
    }
    catch (Exception ex)
    {   
        //handle exception      
        //...

        break;
    }
}
return sb.ToString();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900