.net core 3.0 中的 Microsoft Speech
Microsoft Speech in .net core 3.0
我之前在 .net framework
中使用过 Microsoft Speech(不确定是哪个版本),它确实有效。我现在电脑上没有那个项目。我已经下载并安装了 Runtime 11 and SDK 11,并在我的 .net core 3.0
项目中引用了 C:\Program Files\Microsoft SDKs\Speech\v11.0\Assembly\Microsoft.Speech.dll
中的 .dll
。这是我现在在 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 ...
}
在 xaml 中,我有这些:
<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>
我想这就是我在以前的 Text2Speech 中的全部内容。现在有了所有这些,在我的 .net 核心项目中,它不起作用!
Microsoft Speech Platform SDK 11 与 .NET Core 不兼容。
Microsoft.CognitiveServices.Speech 是新的 .NET 标准兼容 API,可用于 .NET Core。
您会找到 quickstart on GitHub. The official docs is here。
我之前在 .net framework
中使用过 Microsoft Speech(不确定是哪个版本),它确实有效。我现在电脑上没有那个项目。我已经下载并安装了 Runtime 11 and SDK 11,并在我的 .net core 3.0
项目中引用了 C:\Program Files\Microsoft SDKs\Speech\v11.0\Assembly\Microsoft.Speech.dll
中的 .dll
。这是我现在在 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 ...
}
在 xaml 中,我有这些:
<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>
我想这就是我在以前的 Text2Speech 中的全部内容。现在有了所有这些,在我的 .net 核心项目中,它不起作用!
Microsoft Speech Platform SDK 11 与 .NET Core 不兼容。
Microsoft.CognitiveServices.Speech 是新的 .NET 标准兼容 API,可用于 .NET Core。
您会找到 quickstart on GitHub. The official docs is here。