C
C#17mo ago
eduardoA

❔ Problems stopping the speech

Even though Microsoft tell you to call the stop, dosen't stop the speech I have two buttons: play and stop
<Button
Margin="10,0,0,0"
Command="{Binding SpeakButtonCommand}"
Content="{x:Static res:Lang.Read}"
FocusVisualStyle="{x:Null}"
IsEnabled="{Binding IsPlayingEnabled}" />

<Button
Margin="10,0,0,0"
Command="{Binding StopSpeakButtonCommand}"
Content="{x:Static res:Lang.Stop}"
FocusVisualStyle="{x:Null}"
IsEnabled="{Binding IsStopEnabled}" />
<Button
Margin="10,0,0,0"
Command="{Binding SpeakButtonCommand}"
Content="{x:Static res:Lang.Read}"
FocusVisualStyle="{x:Null}"
IsEnabled="{Binding IsPlayingEnabled}" />

<Button
Margin="10,0,0,0"
Command="{Binding StopSpeakButtonCommand}"
Content="{x:Static res:Lang.Stop}"
FocusVisualStyle="{x:Null}"
IsEnabled="{Binding IsStopEnabled}" />
my VM
IsPlayingEnabled = true;
AzureTextToSpeech = new AzureTextToSpeechService();
IsStopEnabled = false;
sb = new();

Text = GetFile(file);

ColorPairs = ColorHelper.GetColors();
SpeakButtonCommand = new AsyncCommand(SpeakButtonction);
StopSpeakButtonCommand = new AsyncCommand(StopSpeakButtonAction);
}



private async Task StopSpeakButtonAction() {
await AzureTextToSpeech.StopSpeechAsync();
IsPlayingEnabled = true;
IsStopEnabled = false;
}

private async Task SpeakButtonction() {
await AzureTextToSpeech.ReadOutLoudAsync(Text!);
IsPlayingEnabled = false;
IsStopEnabled = true;
}
IsPlayingEnabled = true;
AzureTextToSpeech = new AzureTextToSpeechService();
IsStopEnabled = false;
sb = new();

Text = GetFile(file);

ColorPairs = ColorHelper.GetColors();
SpeakButtonCommand = new AsyncCommand(SpeakButtonction);
StopSpeakButtonCommand = new AsyncCommand(StopSpeakButtonAction);
}



private async Task StopSpeakButtonAction() {
await AzureTextToSpeech.StopSpeechAsync();
IsPlayingEnabled = true;
IsStopEnabled = false;
}

private async Task SpeakButtonction() {
await AzureTextToSpeech.ReadOutLoudAsync(Text!);
IsPlayingEnabled = false;
IsStopEnabled = true;
}
and my service
var config = SpeechConfig.FromSubscription(
ConstantsHelpers.AZURE_SPEECH_KEY,
ConstantsHelpers.AZURE_SPEECH_REGION);

switch (lang.Iso6391Name) {
...//
}



speechSynthesizer = new SpeechSynthesizer(config);
await speechSynthesizer.StartSpeakingTextAsync(text);

}


public async Task StopSpeechAsync() {
await speechSynthesizer.StopSpeakingAsync();
}
var config = SpeechConfig.FromSubscription(
ConstantsHelpers.AZURE_SPEECH_KEY,
ConstantsHelpers.AZURE_SPEECH_REGION);

switch (lang.Iso6391Name) {
...//
}



speechSynthesizer = new SpeechSynthesizer(config);
await speechSynthesizer.StartSpeakingTextAsync(text);

}


public async Task StopSpeechAsync() {
await speechSynthesizer.StopSpeakingAsync();
}
The service reads my text, but when I press stop, it dosent work
1 Reply
Accord
Accord17mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.