.net core 3.0 中的 Microsoft Speech [英] Microsoft Speech in .net core 3.0

查看:24
本文介绍了.net core 3.0 中的 Microsoft Speech的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前在 .net framework 中使用过 Microsoft Speech(不确定它是哪个版本),并且确实有效.我的电脑上现在没有那个项目.我已经下载并安装了 Runtime 11SDK 11 并引用了 .dllcode> 在我的 .net core 3.0 项目中,来自 C:Program FilesMicrosoft SDKsSpeechv11.0AssemblyMicrosoft.Speech.dll.这是我现在在我的 ViewModel 中的内容:

<预><代码>...使用 Microsoft.Speech.Synthesis;命名空间读取{公共类 VM:INotifyPropertyChanged{语音合成器合成器;字符串输入文本;公共字符串 InputText { get =>输入文本;设置 { inputText = 值;OnPropertyChanged();} }公共命令说{得到;放;}公共命令暂停{得到;放;}公共命令恢复{得到;放;}公共命令停止{获取;放;}公共虚拟机(){合成器 = 新语音合成器();synth.SetOutputToDefaultAudioDevice();synth.Volume = 75;Speak = new Command(speak, (o) => synth.State != SynthesizerState.Speaking);暂停 = 新命令(暂停, (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.Resume();void stop(object obj) =>synth.SpeakAsyncCancelAll();#region 通知属性更改成员}公共类命令:ICommand ...}

在 xaml 中,我有这些:

<窗口...><Window.DataContext><本地:虚拟机/></Window.DataContext><网格边距=5"><Grid.ColumnDefinitions><ColumnDefinition Width="*"/><ColumnDefinition Width="自动"/></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"/></风格></StackPanel.Resources><Button Content="Speak" Command="{Binding Speak}"/><Button Content="Pause" Command="{绑定暂停}"/><Button Content="Resume" Command="{绑定简历}"/><Button Content="Stop" Command="{绑定停止}"/></StackPanel></网格></窗口>

我想这就是我在之前的 Text2Speech 中所做的一切.现在有了所有这些,在我的 .net 核心项目中,它不起作用!

解决方案

Microsoft Speech Platform SDK 11 与 .NET Core 不兼容.

Microsoft.CognitiveServices.Speech 是符合 .NET Standard 的新 API可用于 .NET Core.

您会找到一个 快速入门.官方文档是这里.

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 FilesMicrosoft SDKsSpeechv11.0AssemblyMicrosoft.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.

这篇关于.net core 3.0 中的 Microsoft Speech的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆