/// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="options"></param>
 /// <param name="runtime"></param>
 /// <param name="logger"></param>
 public BaiduRecognizerProvider(IOptionsMonitor <BaiduSpeechOption> options, IJSRuntime runtime, ILogger <BaiduRecognizerProvider> logger)
 {
     JSRuntime    = runtime;
     SpeechOption = options.CurrentValue;
     Client       = new Baidu.Aip.Speech.Asr(SpeechOption.AppId, SpeechOption.ApiKey, SpeechOption.Secret);
     Logger       = logger;
 }
Beispiel #2
0
        private void button2_Click(object sender, EventArgs e)
        {
            var client = new Baidu.Aip.Speech.Asr(API_KEY, SECRET_KEY);

            client.Timeout = 6000;
            if (openfilePath == "" || comboBox1.Text == "")
            {
                richTextBox1.Text = "请选择语音文件或音频格式";
                return;
            }
            FileInfo fileinfo = new FileInfo(openfilePath);

            byte[]     data = new byte[fileinfo.Length];
            FileStream fs   = fileinfo.OpenRead();

            fs.Read(data, 0, Convert.ToInt32(fs.Length));
            fs.Close();
            string  selectMode = comboBox1.Text.ToString();
            JObject obj        = client.Recognize(data, selectMode, 16000);

            if (obj["err_msg"].ToString() != "success.")
            {
                richTextBox1.Text = obj["err_msg"].ToString();
                return;
            }
            Array  output_ratio = obj["result"].ToArray();
            string ss           = output_ratio.GetValue(0).ToString();

            richTextBox1.Text = ss;
        }