I've used Microsoft Speech previously (not sure which version it was) with .net framework
and it did work. I don't have that project on my PC now. I've downloaded and installed the Runtime 11 and SDK 11 and referenced the .dll
in my .net core 3.0
project from C:\Program Files\Microsoft SDKs\Speech\v11.0\Assembly\Microsoft.Speech.dll
. Here's what I've now in my ViewModel:
.
.
.
using Microsoft.Speech.Synthesis;
namespace Read
{
public class VM : INotifyPropertyChanged
{
SpeechSynthesizer synth;
string inputText;
public string InputText { get => inputText; set { inputText = value; OnPropertyChanged(); } }
public Command Speak { get; set; }
public Command Pause { get; set; }
public Command Resume { get; set; }
public Command Stop { get; set; }
public VM()
{
synth = new SpeechSynthesizer();
synth.SetOutputToDefaultAudioDevice();
synth.Volume = 75;
Speak = new Command(speak, (o) => synth.State != SynthesizerState.Speaking);
Pause = new Command(pause, (o) => synth.State == SynthesizerState.Speaking);
Resume = new Command(resume, (o) => synth.State == SynthesizerState.Paused);
Stop = new Command(stop, (o) => synth.State == SynthesizerState.Speaking || synth.State == SynthesizerState.Paused);
}
void speak(object obj) => synth.SpeakAsync(InputText);
void pause(object obj) => synth.Pause();
void resume(object obj) => synth.Resume();
void stop(object obj) => synth.SpeakAsyncCancelAll();
#region Notify Property Changed Members
}
public class Command : ICommand ...
}
and in xaml, I've these:
<Window ...>
<Window.DataContext>
<local:VM/>
</Window.DataContext>
<Grid Margin="5">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<TextBox Text="{Binding InputText}" AcceptsReturn="True" TextWrapping="Wrap"/>
<StackPanel Grid.Column="1">
<StackPanel.Resources>
<Style TargetType="Button">
<Setter Property="Margin" Value="5 0 0 5"/>
</Style>
</StackPanel.Resources>
<Button Content="Speak" Command="{Binding Speak}"/>
<Button Content="Pause" Command="{Binding Pause}"/>
<Button Content="Resume" Command="{Binding Resume}"/>
<Button Content="Stop" Command="{Binding Stop}"/>
</StackPanel>
</Grid>
</Window>
I think that's all I'd in my previous Text2Speech. Now with all these, in my .net core project, it isn't working!
Microsoft Speech Platform SDK 11 is not compatible with .NET Core.
Microsoft.CognitiveServices.Speech is the new .NET Standard compliant API that is available for .NET Core.
You'll find a quickstart on GitHub. The official docs is here.