winforms 我是否可以从Azure认知服务检索已识别的信任?

yrefmtwq  于 2022-11-17  发布在  其他
关注(0)|答案(1)|浏览(117)

我正在制作语音到文本的应用程序在C夏普窗口形式。它工作正常,运行在visual studio,但
我正在使用Microsoft Azure认知服务来识别此代码。一旦识别了整个过程,我可以在c sharp窗口表单中获得置信度分数吗?
我该如何解决这个问题?
我的代码:

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 Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;
using System.IO;
using System.Threading;

namespace WindowsFormsApp2
{
    public partial class Form1 : Form
    {
        private bool isRecognizing = false;
        private SpeechRecognizer recognizer;

        public Form1()
        {
            InitializeComponent();
        }

        private void initRecognizer()
        {
            
            SpeechConfig config = SpeechConfig.FromSubscription("key", "region");
            if (Properties.Settings.Default.Punctuation)
            {
                config.SetServiceProperty("punctuation", "explicit", ServicePropertyChannel.UriQueryParameter);
            }
            //AudioConfig audioConfig = AudioConfig.FromMicrophoneInput();
            recognizer = new SpeechRecognizer(config/*, audioConfig*/);
            recognizer.Recognized += SpeechRecognizer_Recognized;
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            initRecognizer();

        }

        private void SpeechRecognizer_Recognized(object sender, SpeechRecognitionEventArgs e)
        {
            if (e.Result.Reason == ResultReason.RecognizedSpeech)
            {
                if (e.Result.Text.ToLower().Equals("new line") || e.Result.Text.ToLower().Equals("newline"))
                {
                    SendKeys.SendWait(Environment.NewLine);
                }
                else
                {
                    SendKeys.SendWait(e.Result.Text);
                }

            }
        }

        private void Startstop()
        {
            if (isRecognizing)
            {
                recognizer.StopContinuousRecognitionAsync();
                picture_btn.Image = Properties.Resources.green;
                startToolStripMenuItem.Text = "Start";
                pictureBox1.Enabled = true;                
                isRecognizing = false;
                timer1.Stop();
                timer1.Enabled = false;
            }
            else
            {
                picture_btn.Image = Properties.Resources.red;
                startToolStripMenuItem.Text = "Stop";
                pictureBox1.Enabled = false;
                recognizer.StartContinuousRecognitionAsync();
                isRecognizing = true;
                timer1.Interval = 600;
                timer1.Start();
                timer1.Enabled = true;

            }
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {
            Startstop();
        }

        private void Form1_Move(object sender, EventArgs e)
        {
            if (this.WindowState == FormWindowState.Normal)
            {
                ShowInTaskbar = true;
                notifyIcon1.Visible = true;
                this.Hide();
                notifyIcon1.ShowBalloonTip(1000);
            }
        }

        private void Form1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ShowInTaskbar = true;
            notifyIcon1.Visible = false;
            WindowState = FormWindowState.Normal;
            this.WindowState = FormWindowState.Normal;
            notifyIcon1.Visible = false;

        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        void SettingFormClosed(object sender, FormClosedEventArgs e)
        {
            initRecognizer();
        }

        private void startToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Startstop();
        }


        private void timer1_Tick(object sender, EventArgs e)
        {
            if (picture_btn.Tag.Equals("red"))
            {
                picture_btn.Image = Properties.Resources.grey;
                picture_btn.Tag = "grey";
            }
            else
            {
                picture_btn.Image = Properties.Resources.red;
                picture_btn.Tag = "red";
            }
        }

        private void pictureBox1_Click_1(object sender, EventArgs e)
        {
            var myForm = new Form2();
            myForm.FormClosed += SettingFormClosed;
            myForm.Show();
        }

        private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            this.Show();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                notifyIcon1.Visible = true;
                this.Hide();
                e.Cancel = true;
            }
        }
    }
}
hwazgwia

hwazgwia1#

在深入研究之前,你应该通读服务的文档。文档将涵盖重要的配置方面,并应详细说明限制。


这是 * 语音到文本 * 服务的所有标准资源的登录页,请阅读所有这些资源以了解该服务的设计工作原理,并获得常见场景的代码示例。


这是特定于SpeechRecognizer事件和Results的指南

*认可的偏置和持续时间

本节说明如何取得详细结果。

步骤1 -配置

您需要配置SpeechRecognizer示例以返回 Detailed 输出:

SpeechConfig config = SpeechConfig.FromSubscription("key", "region");
// Detailed output will include confidence factor
config.OutputFormat = OutputFormat.Detailed;

if (Properties.Settings.Default.Punctuation)
{
    config.SetServiceProperty("punctuation", "explicit", ServicePropertyChannel.UriQueryParameter);
}

步骤2 -从Best()扩展方法访问 * 详细信息 *

本节对此进行了记录:识别偏移量和持续时间,但总体思路是调用e.Result.Best()扩展方法来检索有关结果的详细信息。
确保您有以下using语句,以使Best()方法可用:
第一次
例如,您可以从服务中获取这一级别的信息,我还启用了config.RequestWordLevelTimestamps()来获取字级别的时间戳:

相关问题