У меня есть c # winform, которая использует лазурную речь в текст для преобразования речи в текст. Эта winform имеет один флажок для включения / выключения речи и выполняет непрерывное распознавание речи, пока я не закрою окно. Проблема в том, что, когда я проверяю флажок, генерируется только событие начала сеанса, и больше ничего не происходит, не генерируются никакие другие события, такие как Распознавание, Распознано, отменено. Знаете ли вы, что происходит не так?
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;
namespace CsharpSTTform
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private async void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked) await SpeechContinuousRecognitionAsync();
}
public async Task SpeechContinuousRecognitionAsync()
{
// Creates an instance of a speech config with specified subscription key and service region.
// Replace with your own subscription key and service region (e.g., "westus").
var config = SpeechConfig.FromSubscription("api key", "westus");
// Creates a speech recognizer from microphone.
using (var recognizer = new SpeechRecognizer(config))
{
// Subscribes to events.
recognizer.Recognizing += (s, e) =>
{
Console.WriteLine($"RECOGNIZING: Text={e.Result.Text}");
};
recognizer.Recognized += (s, e) =>
{
var result = e.Result;
Console.WriteLine($"Reason: {result.Reason.ToString()}");
if (result.Reason == ResultReason.RecognizedSpeech)
{
Console.WriteLine($"Final result: Text: {result.Text}.");
}
};
recognizer.Canceled += (s, e) =>
{
Console.WriteLine($"\n Recognition Canceled. Reason: {e.Reason.ToString()}, CanceledReason: {e.Reason}");
};
recognizer.SessionStarted += (s, e) =>
{
Console.WriteLine("\n Session started event.");
};
recognizer.SessionStopped += (s, e) =>
{
Console.WriteLine("\n Session stopped event.");
};
// Starts continuous recognition. Uses StopContinuousRecognitionAsync() to stop recognition.
await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);
}
}
}
}
когда я отмечаю флажок, исходный вывод, который я получаю:
Session started event.
The thread 0x3274 has exited with code 0 (0x0).
Через некоторое время я получил этот вывод:
Session started event.
The thread 0x3274 has exited with code 0 (0x0).
The thread 0x5880 has exited with code 0 (0x0).
The thread 0x9e8 has exited with code 0 (0x0).