-2
I have a WPF application that I need to manipulate a textbox. But it gives the following error when running the part of the code that handles the textbox: System.Invalidoperationexception: 'The call thread cannot access this object because it belongs to a different thread. 'The error happens on the line "txt_transcriber.Text = and.Result.Text".
namespace solucao_desktop
{
public partial class TranscriberWindow : Window
{
public TranscriberWindow()
{
InitializeComponent();
}
public void transcribrer()
{
txt_transcriber.Foreground = Brushes.White;
var speechConfig = SpeechConfig.FromSubscription("16c50d2a281d4e9cb0834d4ee3a5d9", "brazilsouth");
speechConfig.SpeechRecognitionLanguage = "pt-BR";
using var audioConfig = AudioConfig.FromDefaultMicrophoneInput();
using var recognizer = new SpeechRecognizer(speechConfig, audioConfig);
var stopRecognition = new TaskCompletionSource<int>();
recognizer.Recognizing += (s, e) => //Enquanto estiver captando algum áudio
{
txt_transcriber.Text = e.Result.Text;
};
recognizer.StartContinuousRecognitionAsync();
Task.WaitAny(new[] { stopRecognition.Task });
}
}