//private const string speechEndpoint = "https://YOUR_LOCATION.api.cognitive.microsoft.com/"; //public async Task<IActionResult> OnGetAsync() //{ // return Page(); //} public async Task <IActionResult> OnPostAsync() { var speechConfig = SpeechConfig.FromSubscription(speechKey, speechLocation); speechConfig.SpeechRecognitionLanguage = "ja-JP"; byte[] readBytes; using var audioInputStream = AudioInputStream.CreatePushStream(); using var reader = new BinaryReader(VoiceFile.OpenReadStream()); do { readBytes = reader.ReadBytes(1024); audioInputStream.Write(readBytes, readBytes.Length); } while (readBytes.Length > 0); var audioConfig = AudioConfig.FromStreamInput(audioInputStream); using var speechRecognizer = new SpeechRecognizer(speechConfig, audioConfig); var result = await speechRecognizer.RecognizeOnceAsync(); if (result.Reason == ResultReason.RecognizedSpeech) { Result = "Œ‹‰Ê:"; RecognizedText = result.Text; } return(Page()); }
protected virtual void StartCore(ExamItemExecutionContext context, CancellationToken token) { IsEndStartCore = false; Logger.DebugFormat("启动项目:{0}", this.Name); Context = context; StartTime = DateTime.Now; State = ExamItemState.Progressing; try { var currentSignal = CarSignalSet.Current; TriggerPoint = context.TriggerPoint; if (currentSignal != null) { StartDistance = currentSignal.Distance; StartAngle = currentSignal.BearingAngle; Logger.DebugFormat("Current 考试项目:{0} 里程 :{1}", this.Name, StartDistance); } else { Logger.Debug("CurrentSignal is null"); } } catch (Exception ex) { Logger.Error("StartCore", ex.Message); } if (StartDistance == 0) { StartDistance = StaticClass.StaticDistance; StartAngle = StaticClass.StaticAngle; Logger.DebugFormat("Static考试项目:{0} 里程 :{1}", this.Name, StartDistance); } //综合评判开始项目没有语音播报 if (ItemCode != ExamItemCodes.CommonExamItem) { if (VoiceFile.Trim() == "滴") { Speaker.SpeakBreakeVoice(); } else { Speaker.PlayAudioAsync(VoiceFile, SpeechPriority.High); } Logger.Debug(VoiceFile, "Playuccess"); } IsEndStartCore = true; }
private List <byte[]> LoadVoiceFile(string name) { if (name == null) { PrintError($"File name is NULL!"); return(null); } if (!this.CacheVoice.ContainsKey(name)) { if (!Interface.Oxide.DataFileSystem.ExistsDatafile($"{this.Title}/{name}")) { PrintError($"Not load voice file: {this.Title}/{name}"); return(null); } VoiceFile file = Interface.Oxide.DataFileSystem.ReadObject <VoiceFile>($"{this.Title}/{name}") as VoiceFile; this.CacheVoice.Add(name, new CacheVoiceData(file.data)); } return(this.CacheVoice[name].GetData()); }
/// <summary> /// /// </summary> /// <returns>true:继续等待,false:已播放完毕</returns> protected virtual bool WaitingForPlayingVoice() { if (Speaker.HasVoice) { return(true); } //todo:是否播放语音 if (!IsPlayedVoice) { var voiceTime = DateTime.Now; Logger.InfoFormat("灯光模拟:加入灯光模拟规则:{0}", VoiceFile); //需要等到语音播放完成之后再进行计算开始时间 Speaker.PlayAudioAsync(VoiceFile, SpeechPriority.Normal, () => { //TODO这样有可能死循环 //需要加一个 while (Speaker.HasVoice) { ; } Thread.Sleep(150); while (Speaker.HasVoice) { ; } //等待语音播报完成之后才可以进行 StartDateTime = DateTime.Now; Logger.InfoFormat("灯光模拟:{0}-语音播报完成:", VoiceFile); IsPlayedVoice = true; }); //写死 //聊城在每句灯光后,添加“噔”的声音,第一句和最后句不加 if (Settings.IsPlayDingVoice) { if (VoiceFile.Contains("请开启前照灯") || VoiceFile.Contains("关闭所有灯光")) { //这两句不播放叮的一声 } else { if (DataBase.Currentversion.DataBaseName.Contains("haikou")) { //使用合成语音“滴” Speaker.PlayAudioAsync("滴", SpeechPriority.Normal); } else { //播放刹车语音 Speaker.SpeakBreakeVoice(); } } } //客户需要 return(true); } return(false); }