private string tempStr = ""; // temporary directory to store the converted audio file private void StartRecognize(string apiRecord) { WavInfo wav = ClassUtils.GetWavInfo(apiRecord); //数据量 = (采样频率 × 采样位数 × 声道数 × 时间) / 8 //if ((double)(wav.datasize * 8) / (wav.dwsamplespersec * wav.wbitspersample * wav.wchannels) > 60) //{ // labelInfo.ForeColor = Color.HotPink; // labelInfo.Text = "Error: The audio file is too large!"; //} // 非8k/16k, 16bit 位深, 单声道的,进行格式转换 if (apiRecord.EndsWith(".mp3", StringComparison.CurrentCultureIgnoreCase) || int.Parse(wav.dwsamplespersec.ToString()) != 16000 || int.Parse(wav.wbitspersample.ToString()) != 16 || int.Parse(wav.wchannels.ToString()) != 1) { apiRecord = ClassUtils.Convert2Wav(apiRecord); // convert audio file to 16k,16bit wav tempStr = apiRecord; } labelInfo.ForeColor = Color.SpringGreen; labelInfo.Text = "Recognizing..."; KeyValuePair <string, string> keyVal = (KeyValuePair <string, string>)comboBoxLan.SelectedItem; speechModel.APILanguage = keyVal.Value; // fetch the value in comboBox if (backgroundWorker.IsBusy != true) { this.backgroundWorker.RunWorkerAsync(); // do the time consuming task } }
public static string checkAudio(string fileName) { WavInfo wav = ClassUtils.GetWavInfo(fileName); //数据量 = (采样频率 × 采样位数 × 声道数 × 时间) / 8 // 非8k/16k, 16bit 位深, 单声道的,进行格式转换 if (fileName.EndsWith(".mp3", StringComparison.CurrentCultureIgnoreCase) || int.Parse(wav.dwsamplespersec.ToString()) != 16000 || int.Parse(wav.wbitspersample.ToString()) != 16 || int.Parse(wav.wchannels.ToString()) != 1) { fileName = ClassUtils.Convert2Wav(fileName); // convert audio file to 16k,16bit wav } return(fileName); }