資源簡介
1.使用科大訊飛語音喚醒、語音聽寫服務,內含MSCDLL.CS類文件,可直接調用;
2.利用system.Audio,NAudio從聲卡中錄音,獲取語音信息;根據說話音量大小,設定閾值,作為語音的結束標志;可做到實時聽寫;
3.程序默認執行語音喚醒模塊,當語音喚醒標志符awaken_flag == true時,關閉喚醒服務,打開聽寫服務;
4.根據聽寫的文本,自做簡單語音識別算法,并填寫在相應的textbox中,適合特定場景開發;
4.同時利用System.Speech.Synthesis可以對文本進行朗讀操作;
5.下載之后,請自行去訊飛申請語音聽寫服務,并替換dll文件
2.利用system.Audio,NAudio從聲卡中錄音,獲取語音信息;根據說話音量大小,設定閾值,作為語音的結束標志;可做到實時聽寫;
3.程序默認執行語音喚醒模塊,當語音喚醒標志符awaken_flag == true時,關閉喚醒服務,打開聽寫服務;
4.根據聽寫的文本,自做簡單語音識別算法,并填寫在相應的textbox中,適合特定場景開發;
4.同時利用System.Speech.Synthesis可以對文本進行朗讀操作;
5.下載之后,請自行去訊飛申請語音聽寫服務,并替換dll文件
代碼片段和文件信息
using?System;
using?System.Collections.Generic;
using?System.ComponentModel;
using?System.Data;
using?System.Drawing;
using?System.Linq;
using?System.Text;
using?System.Threading.Tasks;
using?System.Windows.Forms;
using?NAudio.Wave;
using?VoiceRecorder.Audio;
using?System.Runtime.InteropServices;
using?System.Threading;
using?System.Speech.Synthesis;
namespace?SpeachTest
{
????public?partial?class?Form1?:?Form
????{
????????//錄音參數
????????
????????private?WaveIn?waveIn;
????????private?AudioRecorder?recorder;
????????private?float?lastPeak;//說話音量
????????float?secondsRecorded;
????????float?totalBufferLength;
????????int?Ends?=?5;
????????private?const?int?BUFFER_SIZE?=?4096;
????????List?VoiceBuffer?=?new?List();
????????MSCDLL.ivw_ntf_handler?IVW_callback;
????????//語音交互參數
????????string?session_begin_params;//喚醒參數??
????????string?session_begin_paramsA;//聽寫參數
????????IntPtr?session_id?=?IntPtr.Zero;
????????string?rec_result?=?string.Empty;
????????string?hints?=?“success“;
????????AudioStatus?aud_stat?=?AudioStatus.ISR_AUDIO_SAMPLE_CONTINUE;????????
????????int?errcode?=?(int)ErrorCode.MSP_SUCCESS;
????????public?bool?awaken_flag?=?false;?//語音喚醒標志位?false為未喚醒,true為已喚醒
????????public?bool?dictation_flag?=?false;?//語音聽寫標志位?false為未開始聽寫,?true為正在聽寫
????????string?last_Result?=?““;?//上次語音聽寫結果
????????//DateTime?timerLast?timerNext;
????????int?stop_Count?=?40;//經過一段時間未有語音輸入之后,關閉語音聽寫
????????int?stop_time?=?10;//語音空置保持時間
????????bool?input_flag?=?false;
????????int?number?=?0;//輸入框的編號
????????DateTime?dictation_end_time?=?DateTime.Now;//語音聽寫結束的時間
????????public?Form1()
????????{
????????????InitializeComponent();
????????????SpeechRecognition();
????????????totalBufferLength?=?0;
????????????recorder?=?new?AudioRecorder();//錄音設備
????????????recorder.BeginMonitoring(-1);
????????????recorder.SampleAggregator.MaximumCalculated?+=?OnRecorderMaximumCalculated;
????????????if?(waveIn?==?null)
????????????{
????????????????waveIn?=?CreateWaveInDevice();
????????????}
????????????waveIn.WaveFormat?=?new?WaveFormat(16000?1);
????????????waveIn.StartRecording();
????????????timer1.Enabled?=?true;
????????????timer2.Enabled?=?true;
????????}
????????public?void?SpeechRecognition()//初始化語音識別
????????{
????????????awaken_flag?=?false;
????????????last_Result?=?““;
????????????int?ret?=?(int)ErrorCode.MSP_SUCCESS;
????????????string?login_params?=?string.Format(“appid=5e5c****word_dir=?.?“);//appid和msc.dll要配套
????????????#region?參數
????????????/*
????????????*sub:本次識別請求的類型??iat?連續語音識別;???asr?語法、關鍵詞識別默認為iat
????????????*domain:領域??????iat:連續語音識別??asr:語法、關鍵詞識別????search:熱詞???video:視頻????poi:地名??music:音樂????默認為iat。?注意:sub=asr時,domain只能為asr
????????????*language:語言????zh_cn:簡體中文??zh_tw:繁體中文??en_us:英文????默認值:zh_cn
????????????*accent:語言區域????mandarin:普通話????cantonese:粵語????lmz:四川話?默認值:mandarin
????????????*sample_rate:音頻采樣率??可取值:16000,8000??默認值:16000???離線識別不支持
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件????????187??2020-03-02?15:43??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\App.config
?????文件?????627244??2020-03-17?15:23??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\audio\awake.wav
?????文件?????627244??2020-03-18?09:42??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\audio\awake1.wav
?????文件?????223276??2020-03-18?09:49??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\audio\awake2.wav
?????文件?????????12??2020-03-02?17:21??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\3ac134c735f78453223914867152cb93\u.data
?????文件?????????84??2020-03-02?17:21??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\3ac134c735f78453223914867152cb93\urec.data
?????文件????????197??2020-03-20?11:02??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\8b2e343da7d822d13fc2b68a2f1b0ba4\kivw.dat
?????文件?????????12??2020-03-20?10:54??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\8b2e343da7d822d13fc2b68a2f1b0ba4\u.data
?????文件?????????85??2020-03-20?10:54??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\8b2e343da7d822d13fc2b68a2f1b0ba4\urec.data
?????文件??????11102??2020-03-20?10:07??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxja-NOxd3iaalysChOl1cPRo.log
?????文件??????11106??2020-03-20?09:57??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxjaBcOcL3oaa5qja9Yu80BMm.log
?????文件??????11107??2020-03-20?10:36??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxjainOvKdFaaWVGHHTmDl0ZO.log
?????文件??????11103??2020-03-20?09:59??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxjakHOTpDxaaWmpm8ZwMcwTh.log
?????文件??????11106??2020-03-20?10:23??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxjao6OJKaLaaarMkTom+WaVZ.log
?????文件??????11107??2020-03-20?10:38??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxjaq8OIpr9aamxQkTCl-ik7v.log
?????文件??????11103??2020-03-20?10:51??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxjaRQOY0fjaaH4fkvDCbWkkl.log
?????文件??????11163??2020-03-20?10:48??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxjaS7OOjrvaakfBmI+t48dQZ.log
?????文件??????11097??2020-03-20?09:16??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxjHIFOncp9aaPNNHIH1XEHpz.log
?????文件??????11104??2020-03-20?09:18??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxjHO-OnUWtaadM7dw4t+utQ2.log
?????文件??????11104??2020-03-20?08:39??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxjHw1OWRLYaaa3M0NZ06UHZs.log
?????文件??????10448??2020-03-20?09:01??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxjHy-OkSkRaam10aJECSUBH9.log
?????文件??????11229??2020-03-20?10:54??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxjwH0OYiFaaaH0ICZwHzvdsU.log
?????文件??????11103??2020-03-20?11:02??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxjwlhO22voaaklTu3VuC0Hfz.log
?????文件??????11108??2020-03-19?09:19??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxT+4Y4WoOoaadNEuv7BSft3u.log
?????文件??????11110??2020-03-19?08:56??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxT+Bc4dlgOaat88PjSl8TBoS.log
?????文件??????11110??2020-03-19?09:27??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxT+KK4CpEWaatT3aXJk-4lFx.log
?????文件??????11108??2020-03-19?09:02??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxT+nt41JFmaa525tolmD6tli.log
?????文件??????11106??2020-03-19?09:24??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxT+Ol4021daauRdHWlw+3Hhi.log
?????文件??????11104??2020-03-19?09:01??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxT+pj41ynjaaHpl1zVC9sHaK.log
?????文件??????11110??2020-03-19?08:57??SpeachTest(喚醒+聽寫)?-?語音輸入\SpeachTest\bin\Debug\msc\civw1P1HHBHxT+uA4deI5aadD95DxCnVPWE.log
............此處省略102個文件信息
評論
共有 條評論