public void AwaitOnCompleted <TAwaiter, TStateMachine>(ref TAwaiter awaiter, ref TStateMachine stateMachine) where TAwaiter : INotifyCompletion where TStateMachine : IAsyncStateMachine { switch (awaiter) { case IBreakable breakableAwaiter: _inner = breakableAwaiter; awaiter.OnCompleted(_continuation); break; case SelfScopeAwaiter selfScopeAwaiter: selfScopeAwaiter.Value = Task.Scope; awaiter.OnCompleted(_continuation); break; case SelfDisposeAwaiter selfDisposeAwaiter: selfDisposeAwaiter.Value = Task._Dispose; awaiter.OnCompleted(_continuation); break; default: Asr.Fail("passed unbreakable awaiter"); break; } }
//语音识别 public void recoVideo() { Thread.Sleep(2000); if (client == null) { var API_KEY = "uz804M95AKkq5OffLCB9GD3q"; var SECRET_KEY = "IZxCofo7vFRYiPKhXqdmh2Da51MrhDKA"; client = new Baidu.Aip.Speech.Asr(API_KEY, SECRET_KEY); } for (int i = 1; i < number; i++) { try { var data = FileUtil.getFileVideo(videoPath, i + ".pcm"); client.Timeout = 12000; // 若语音较长,建议设置更大的超时时间. ms var result = client.Recognize(data, "pcm", 16000, dic); if (result["result"] != null) { String value = result["result"][0].ToString(); tranText(value, i, captionDic); } } catch (Exception e) { Console.WriteLine(e.Message); tranText(e.Message, i, captionDic); } } }
public void MultipleDispose() { var visited = false; Sample(); Assert.IsTrue(visited); var dispose1 = React.Scope(out var scope1); var r = Outer(scope1); dispose1.Dispose(); Asr.IsTrue(r.GetAwaiter().IsCompleted); async Routine Outer(IScope scope) { var res = await Sample().DisposeOn(scope); Asr.IsFalse(res.HasValue); } async Routine <int> Sample() { visited = true; await _Never.Instance; return(42); } }
private Asr CreateSpeechClient() { var client = new Asr(App.AppId, App.ApiKey, App.SecretKey); client.Timeout = 120000; return(client); }
static TargetEntry Locate2(TTarget o) { var id = _generator.HasId(o, out var firstTime); Asr.IsFalse(firstTime); return(_Registry[id]); }
// 识别本地文件 /// <summary> /// /// </summary> /// <param name="filePath">文件地址</param> /// <param name="fileType">文件类型</param> /// <param name="rate">采样率</param> /// <param name="lan">识别语言,默认lan=zh,设置为lan=en后,返回结果一定为英文</param> public List <string> AsrData(string filePath, string fileType, int rate, string lan) { var data = File.ReadAllBytes(filePath); Dictionary <string, object> para = new Dictionary <string, object>(); para.Add("lan", lan); if ("pcm".Equals(fileType) || "wav".Equals(fileType)) { string API_KEY = "PhUlgrvjGmIaSuPAvn5CWbAE"; string SECRET_KEY = "fDZXemDEyPc6dcAfT8YxkgQuN29kVjwC"; Asr asr = new Asr(API_KEY, SECRET_KEY); JObject result = asr.Recognize(data, fileType, rate, para); List <string> res = new List <string>(); if ("0".Equals(result["err_no"].ToString())) { JArray jaResult = JArray.Parse(result["result"].ToString()); foreach (JToken jt in jaResult) { res.Add(jt.ToString()); } } return(res); } else { return(null); } }
public void StopAndGetResult() { string result = ""; Microphone.End(null); var data = Asr.ConvertAudioClipToPCM16(_clipRecord); StartCoroutine(_asr.Recognize(data, s => { result = s.result != null && s.result.Length > 0 ? s.result[0] : "未识别到声音"; lastContent = result; if (Eve解析完成 != null && result != "未识别到声音") { Eve解析完成(result); } else if (Eve未检测到声音 != null && result == "未识别到声音") { Eve未检测到声音(); } //Debug.Log("结束录音:" + result); })); if (Eve结束录音 != null) { Eve结束录音(); } }
public void GetOrFail(out T value) { if (!TryGet(out value)) { Asr.Fail($"Option<{typeof(T).Name}> has no value"); } }
public static (IPublish pub, ISubscribe sub) PubSub(this IScope scope) { Asr.IsFalse(scope.Disposing); var subject = new Subject(scope); return(subject, subject); }
/// <summary> /// 开始识别按钮 /// /// dev_pid 可选参数 /// 1536 普通话(支持简单的英文识别) 搜索模型 无标点 支持自定义词库 http://vop.baidu.com/server_api /// 1537 普通话(纯中文识别) 输入法模型 有标点 不支持自定义词库 http://vop.baidu.com/server_api /// 1737 英语 无标点 不支持自定义词库 http://vop.baidu.com/server_api /// 1637 粤语 有标点 不支持自定义词库 http://vop.baidu.com/server_api /// 1837 四川话 有标点 不支持自定义词库 http://vop.baidu.com/server_api /// 1936 普通话远场 远场模型 有标点 不支持自定义词库 http://vop.baidu.com/server_api /// 80001语音识别极速版(收费) /// 80001 普通话 极速版输入法模型 有标点 支持自定义词库 http://vop.baidu.com/pro_api /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { var type = videoType.Text; var filePath = this.filePath.Text; //设置语音识别应用的账号信息(百度智能云管理中心) APP_ID/API_KEY/SECRET_KEY //demo里的账号 //var APP_ID = "14433392"; //var API_KEY = "C7WMYgLeWv3Wm2yogwv5gD08"; //var SECRET_KEY = "xcvwiwikALBDBaIcGisNQ6aQImtj3qua"; //请更改成自己的账号 string APP_ID = "16982575"; string API_KEY = "0kC4dDwWl3hqo2xz2c4113ZP"; string SECRET_KEY = "8aneCyn9KVAWjGKAIfpcr3vMCFt19kIb"; var client = new Asr(APP_ID, API_KEY, SECRET_KEY); client.Timeout = 120000; // 若语音较长,建议设置更大的超时时间. ms // 可选参数 var options = new Dictionary <string, object> { { "dev_pid", 1536 } }; var result = client.Recognize(File.ReadAllBytes(filePath), type.TrimStart('.'), 16000, options); voiceResult.Text = Convert.ToString(result); result.TryGetValue("result", out JToken resultStr); if (Convert.ToString(resultStr) != "") { voiceResult.Text = Convert.ToString(resultStr); } }
private void OnClickStopButton() { StartButton.gameObject.SetActive(false); StopButton.gameObject.SetActive(false); DescriptionText.text = "转换中..."; Microphone.End(null); //清空 var data = Asr.ConvertAudioClipToPCM16(_clipRecord); //转换成byte数据 //将byte传入 然后转换 StartCoroutine(_asr.Recognize(data, s => { //转换回掉函数 文本=转换结果不为空且结果长度大于0 否则为“未识别声音” if (s.result == null) { DescriptionText.text = "未识别到声音"; StartButton.gameObject.SetActive(true); } else { RecognitionResult(s.result[0]); } })); }
public void Awake() { CtrlButton = uispeech.Get<GameObject>("CtrlBtn").GetComponent<Button>(); //CtrlButton.onClick.Add(() => { Debug.Log("1111"); }); //初始化事件 trigger = CtrlButton.gameObject.GetComponent<EventTrigger>(); entry1 = new EventTrigger.Entry(); entry2 = new EventTrigger.Entry(); entry3 = new EventTrigger.Entry(); entry1.eventID = EventTriggerType.PointerEnter; entry2.eventID = EventTriggerType.PointerDown; entry3.eventID = EventTriggerType.PointerExit; //这里是分别绑定 //绑定鼠标进入事件 entry1.callback = new EventTrigger.TriggerEvent(); entry1.callback.AddListener(M); trigger.triggers.Add(entry1); //绑定鼠标点击事件 entry2.callback = new EventTrigger.TriggerEvent(); entry2.callback.AddListener(N); trigger.triggers.Add(entry2); //绑定鼠标离开事件 entry3.callback = new EventTrigger.TriggerEvent(); entry3.callback.AddListener(F); trigger.triggers.Add(entry3); //初始化百度Api工具 asr = new Asr(APIKey, SecretKey); tts = new Tts(APIKey, SecretKey); }
static TEvents Locate(TTarget o) { var id = _generator.HasId(o, out var firstTime); Asr.IsFalse(firstTime); return(_eventRegistry[id]); }
public static bool TryLocate(TTarget key, out TEvents value) { var id = _generator.HasId(key, out var firstTime); Asr.IsFalse(firstTime); return(_eventRegistry.TryGetValue(id, out value)); }
// Start is called before the first frame update void Start() { _asr = new Asr(apiKey, secretKey); StartCoroutine(_asr.GetAccessToken()); StartCoroutine(Timer()); _clipRecord = Microphone.Start(null, false, 30, 16000); }
public void Dispose() { if (Disposed) { return; } if (Disposing) { // Asr.Fail("Self-looping dispose call"); return; } Disposing = true; Action cur = null; while (TryDequeue(ref cur)) { Asr.IsFalse(Disposed); cur.Invoke(); } _stack.Clear(); _stack = null; Disposed = true; }
public CommonSpeechRec(SpeechAppData appData, string format, int devPid) { _asr = new Asr(appData.appId, appData.apiKey, appData.secretKey); this._speechFormat = format; this._devPid = devPid; }
public T GetOrFail() { if (!TryGet(out var value)) { Asr.Fail($"Option<{typeof(T).Name}> has no value"); } return(value); }
private static void AsrBgm(String token, String endpoint) { String dataUrl = "https://obs-test-llg.obs.cn-north-1.myhwclouds.com/bgm_recognition"; // The obs url of file // post data by obs url String reslut = Asr.AsrBgmToken(token, dataUrl, endpoint); Console.WriteLine(reslut); Console.ReadKey(); }
public BaiduAsrProxy(string appKey, string appSecret) { if (null != client) { return; } client = new Asr(appKey, appSecret) { Timeout = 60000 }; }
private JObject Baidu_RecognizeByAPI(string filePhysicsPath, bool isEn) { Asr _asrClient = new Asr("TmZSp2x7nZXlPIW6GapK45XG", "BuWaLotBu4ho1GnblaMbue3ppryGuOYG "); var data = File.ReadAllBytes(filePhysicsPath); Dictionary <string, object> dic = new Dictionary <string, object>(); dic.Add("lan", "en"); var result = _asrClient.Recognize(data, "WAV", 8000, dic); return(result); }
private static void AsrBgm(String token, String endpoint) { // The OBS link must match the region, and the OBS resources of different regions are not shared String dataUrl = "https://obs-test-llg.obs.cn-north-1.myhuaweicloud.com/bgm_recognition"; // post data by obs url String reslut = Asr.AsrBgmToken(token, dataUrl, endpoint); Console.WriteLine(reslut); Console.ReadKey(); }
void Start() { _asr = new Asr(APIKey, SecretKey); StartCoroutine(_asr.GetAccessToken()); StartButton.gameObject.SetActive(true); StopButton.gameObject.SetActive(false); DescriptionText.text = ""; StartButton.onClick.AddListener(OnClickStartButton); StopButton.onClick.AddListener(OnClickStopButton); light1.SetActive(false); light2.SetActive(false); light3.SetActive(false); light4.SetActive(false); light5.SetActive(false); light6.SetActive(false); light7.SetActive(false); light8.SetActive(false); lightmain.SetActive(false); // dog = ;//生成敌人 dog = Random.Range(1, 8); //生成敌人 patient.transform.localScale = new Vector3(50, 50, 60); // dog = 1; if (dog == 1) { Instantiate(patient, new Vector3(10.902f, 0.5f, -3.24f), Quaternion.Euler(-180, -90, 0)); } else if (dog == 2) { Instantiate(patient, new Vector3(10.902f, 0.5f, 9.25f), Quaternion.Euler(-180, -90, 0)); } else if (dog == 3) { Instantiate(patient, new Vector3(10.902f, 0.5f, 21.52f), Quaternion.Euler(-180, -90, 0)); } else if (dog == 4) { Instantiate(patient, new Vector3(10.902f, 0.5f, 34.17f), Quaternion.Euler(-180, -90, 0)); } else if (dog == 5) { Instantiate(patient, new Vector3(-5.31f, 0.5f, 36), Quaternion.Euler(-180, -90, 0)); } else if (dog == 6) { Instantiate(patient, new Vector3(-5.31f, 0.5f, 23.47f), Quaternion.Euler(-180, -90, 0)); } else if (dog == 7) { Instantiate(patient, new Vector3(-5.31f, 0.5f, 14.14f), Quaternion.Euler(-180, -90, 0)); } else if (dog == 8) { Instantiate(patient, new Vector3(-5.31f, 0.5f, 1.92f), Quaternion.Euler(-180, -90, 0)); } Debug.Log(dog); patText.text = "Your patient is in ward No." + dog; }
// Microphone is not supported in Webgl #if !UNITY_WEBGL void Start() { _asr = new Asr(APIKey, SecretKey); StartCoroutine(_asr.GetAccessToken()); StartButton.gameObject.SetActive(true); StopButton.gameObject.SetActive(false); DescriptionText.text = ""; StartButton.onClick.AddListener(OnClickStartButton); StopButton.onClick.AddListener(OnClickStopButton); }
public void Unsubscribe(Action dispose) { if (Disposed || Disposing) { Asr.Fail("Cannot unsubscribe during or after disposal"); return; } var any = _stack.Remove(dispose); Asr.IsTrue(any, "Delegate not found: make sure it's the same which was passed to OnDispose"); }
private Asr aipClient; // 百度语音识别SDK void Start() { aipClient = new Asr(API_KEY, SECRET_KEY); // 创建SDK的实例 aipClient.Timeout = 6000; // 超时时长为6000毫秒 accessToken = GetAccessToken(); // 保存当前应用的Token // 获取自定义Button的实例 listenBtn = GetComponentInChildren <ListenButton>(); listenBtn.OnStartRecordEvent += StartRecord; listenBtn.OnStopRecordEvent += StopRecord; recordSource = GetComponent <AudioSource>(); }
void Start() { _asr = new Asr(APIKey, SecretKey);//实例 StartCoroutine(_asr.GetAccessToken()); StartButton.gameObject.SetActive(true); StopButton.gameObject.SetActive(false); DescriptionText.gameObject.SetActive(true); StartButton.onClick.AddListener(OnClickStartButton);//开始按钮监听 StopButton.onClick.AddListener(OnClickStopButton); SceneController.Instance.bgm.SetActive(false); }
////每一振处理那一帧接收的音频文件 //float GetMaxVolume() //{ // float maxVolume = 0f; // //剪切音频 // float[] volumeData = new float[128]; // int offset = Microphone.GetPosition(null) - 128 + 1; // if (offset < 0) // { // return 0; // } // _clipRecord.GetData(volumeData, offset); // for (int i = 0; i < 128; i++) // { // float tempMax = volumeData[i];//修改音量的敏感值 // if (maxVolume < tempMax) // { // maxVolume = tempMax; // } // } // return maxVolume; //} void Start() { _asr = new Asr(APIKey, SecretKey); StartCoroutine(_asr.GetAccessToken()); StartButton.gameObject.SetActive(true); StopButton.gameObject.SetActive(false); DescriptionText.text = ""; StartButton.onClick.AddListener(OnClickStartButton); StopButton.onClick.AddListener(OnClickStopButton); // _clipRecord = Microphone.Start(null, false, 30, 16000); }
public static void Deregister(TTarget target) { var hash = _generator.GetId(target, out var firstTime); Asr.IsFalse(firstTime); if (_Registry.TryGetValue(hash, out var t)) { _Registry[hash].Deregistered = true; } else { Asr.Fail("No such key"); } }
private void StopRecording() { //此时判断是否处于说话状态,如果是说话状态则将按钮复位,并上传说话内容 if (StartSpeech) { //上传内容 Log.Debug("麦克风停止录音"); Microphone.End(null); //转换格式 var data = Asr.ConvertAudioClipToPCM16(clipRecord); asr.Recognize(data, s => { Log.Debug("进来了"); if (s.result == null && s.result.Length < 0) { Log.Debug("结果为空,表示麦克风未识别到声音"); //提示有问题,复位 entry2.callback.AddListener(N); StartSpeech = false; } else { //有结果,发送给机器人进行语音回复 tts.Synthesis(s.result[0], r => { if (r.Success) { //正常播放 Log.Debug("合成成功,正在播放,声音有几秒:" + audioSource.clip.length); audioSource.clip = r.clip; audioSource.Play(); //复位 entry2.callback.AddListener(N); StartSpeech = false; } else { //这是出问题了 Debug.Log(s.err_msg); //提示有问题,复位 entry2.callback.AddListener(N); StartSpeech = false; } }); } }); } }