文本转语音SAPI5使用其他语音时的AccessViolationException

本文关键字:语音 其他 AccessViolationException SAPI5 文本 | 更新日期: 2023-09-27 17:50:31

我已经为SAPI5 Eliska22k安装了捷克语音。它在Windows 7上运行良好。现在我在windows 8中调用Speak方法它给了我Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

我也尝试使用SpeechSynthesizer从。net System.Speech。它也可以看到语音Eliska22k安装(在W7上,它只适用于SAPI5),但它不会写任何异常,它只是不会启动。在SelectVoice("Eliska22k")方法程序刚刚退出。

默认语音在SAPI5中也可以正常工作。

我已经安装了SpeechPad,它与语音Eliska22k一起工作。我找不到问题所在。

SpeechSynthesizer voice = new SpeechSynthesizer();
voice.SelectVoice("Eliska22k");// here program just exit without any exeption
voice.Rate = 2;
voice.SpeakAsync("Ahoj, jak se máš?");

SAPI5

SpVoice voice = new SpVoice();
voice.Voice = voice.GetVoices().Item(6);// index of eliska voice
voice.Rate = 2;
voice.Speak("Ahoj, jak se máš?", SpeechVoiceSpeakFlags.SVSFlagsAsync);//here occurs exeption

谢谢你的建议

文本转语音SAPI5使用其他语音时的AccessViolationException

据我所知,这个软件还不兼容Windows 8。

Xtranormal开发了这些语音包,将其与文本一起添加到动画软件中。

查看PC World上对该软件的评论,发现其2.5测试版的规格适用于Windows XP和Windows Vista。

请注意,PCWorld的评论是在2010年进行的。对Windows 7的支持在此审查后集成。

注意到Windows 7发布的滞后和该软件升级到Windows 7兼容也加强了我的论点,这还不是Windows 8准备好了。(Windows 7发布5个月后PC界评测了这款软件,它不兼容Windows 7, Windows 8还没出来那么久,升级软件需要时间;)

在他们自己的网站上查看他们的技术细节,建议最迟使用Windows 7。

对我来说,这表明他们还没有把它更新到Windows 8。

(作为一个额外的脚注,YouTube上没有一个关于这个软件与windows 8的教程,但是有很多其他操作系统的教程,这些天人们做了一个关于任何东西的教程,而这个操作系统缺乏一个(尽管应用程序在过去的两年里越来越流行,再次表明,没有windows 8;)

脚注:Software Informer是一个几乎对所有可用软件进行评论的网站,较旧的版本收到了2 - 3条评论,而最新版本提交了260条,因此已知的受欢迎程度有所增加)

脚注2;我专注于软件的原因是因为声音最初是为软件设计的。因此,如果声音接收到升级,他们打算首先使用的软件可能会首先升级)

你认为他们会在他们的网站上说他们支持什么操作系统:/

不确定这是否是答案,但每当我试图重复使用相同的媒体元素来一遍又一遍地播放不同的流(例如,用户是按钮混合)时,我都会遇到相同的确切错误。解决方案是使用显式GC.Collect()。虽然有5个媒体元素也有点不错,因为它似乎加快了停止和重新启动音频的速度。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Media.SpeechSynthesis;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238
namespace SpeechMark
{
  /// <summary>
  /// An empty page that can be used on its own or navigated to within a Frame.
  /// </summary>
  public sealed partial class BlankPage1 : Page
  {
    public BlankPage1()
    {
      this.InitializeComponent();
      m_button.Click += m_button_Click;
      m_audioPlayerPool = new MediaElement[5];
      for(int index = 0; index < m_audioPlayerPool.Length; index++)
      {
        var audioPlayer = new MediaElement();
        audioPlayer.AutoPlay = true;
        m_audioPlayerPool[index] = audioPlayer;
        m_grid.Children.Add(audioPlayer);
      }
      m_textToSpeech = new SpeechSynthesizer();
    }
    async void m_button_Click(object sender, RoutedEventArgs e)
    {
      m_button.IsEnabled = false;
      if (m_audioPlayer != null)
      {
        m_audioPlayer.Stop();
      }
      if (m_stream != null)
      {
        m_stream.Dispose();
        m_stream = null;
      }
      GC.Collect();
      m_audioPlayer = m_audioPlayerPool[m_nextAudioPlayerToUse];
      m_nextAudioPlayerToUse = (m_nextAudioPlayerToUse + 1) % m_audioPlayerPool.Length;
      string ssml = "<speak version='"1.0'" xmlns='"http://www.w3.org/2001/10/synthesis'" xml:lang='"en'"><voice gender='"female'" xml:lang='"en'"><prosody rate='"1'">how are you doing</prosody><mark name='"utteranceComplete'"/></voice></speak>";
      m_stream = await m_textToSpeech.SynthesizeSsmlToStreamAsync(ssml);
      m_audioPlayer.SetSource(m_stream, m_stream.ContentType);
      m_button.IsEnabled = true;
    }
    private MediaElement m_audioPlayer;
    private MediaElement[] m_audioPlayerPool;
    private int m_nextAudioPlayerToUse = 0;
    private SpeechSynthesizer m_textToSpeech;
    public SpeechSynthesisStream m_stream { get; set; }
  }
}
xaml:

<Page
    x:Class="SpeechMark.BlankPage1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:SpeechMark"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Grid x:Name="m_grid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
    <Button x:Name="m_button" Height="128" Margin="446,303,0,337" Width="256"/>
  </Grid>
</Page>