【发布时间】:2021-02-10 05:37:20
【问题描述】:
我正在做一个语音合成项目,我决定尝试使用 Microsoft.Speech 命名空间而不是内置的 System.Speech 命名空间,因为 Microsoft 没有修复内存泄漏 here 并建议使用Microsoft.Speech 作为一种解决方法。
当我运行下面的程序时,当它调用GetInstalledVoices 时,我得到一个NullReferenceException。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Speech.Synthesis;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SpeechSynthesizer synth = new SpeechSynthesizer();
synth.GetInstalledVoices();
}
}
}
当我运行下一个程序时,当它调用Speak 时,我得到一个UnauthorizedAccessException(我以管理员身份运行)。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Speech.Synthesis;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
SpeechSynthesizer synth = new SpeechSynthesizer();
synth.Speak("exception");
}
}
}
我在 Windows 8 x64 上运行 VS Express 2012,并且项目配置为 x64。我为 Microsoft 语音安装了 x64 运行时和 SDK,并从http://www.microsoft.com/en-us/download/details.aspx?id=27224 安装了 en-us 语言包。我什至尝试下载 x86 运行时和 SDK 并将我的项目更改为 x86,但这会导致 PlatformNotSupportedException。
我是否缺少其他一些安装,或者我的平台不支持 Microsoft.Speech 命名空间?如果我将using Microsoft.Speech.Synthesis 更改为using System.Speech.Synthesis,除了我提到的内存泄漏之外,一切都很好,我现在可能可以摆脱它,因为这是一个爱好应用程序,不是为了工作。
【问题讨论】:
-
您是否尝试在 x86 中构建应用程序?
-
@FelicePollano,是的,但它给了我一个
PlatformNotSupportedException,即使我当时指向的是 x86 SDK 程序集。 -
我想我看到了泄漏,ConvertTextFrag.FreeTextSegment() 方法中缺少一行代码。添加 fragment.Free() 应该可以修复泄漏。有点遗憾,这无法解决,似乎没有人对此足够关心以通过 Microsoft 支持解决此问题。可能有太多的爱好项目。反馈文章已经提到了声音问题,听起来你也看到了。
标签: c# text-to-speech speech-synthesis