【问题标题】:Google TTS speech issue谷歌 TTS 语音问题
【发布时间】:2014-05-16 15:30:39
【问题描述】:

我正在尝试让 Google TTS 语音正常工作,因为 Windows RT/Metro 不包含 System.Speech 的定义。下面的代码编译没有错误,但没有说什么。我已经调试并检查了“ListBox.SelectedItem”是否包含文本,确实如此。

调用的库:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Windows.Foundation;
using Windows.Foundation.Collections;
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;
using Windows.UI.Popups;
using System.Net.Http;

这就是我调用 myMediaElement 的方式:

MediaElement myMediaElement = new MediaElement();

这就是我想要做的:

private void RepeatWord_Click(object sender, RoutedEventArgs e)
{
    string pathx = "http://translate.google.com/translate_tts?tl=en&q=" + ListBox.SelectedItem.ToString();
    myMediaElement.Source = new Uri(pathx, UriKind.RelativeOrAbsolute);
    myMediaElement.Play();
}

【问题讨论】:

    标签: c# visual-studio-2012 windows-8


    【解决方案1】:

    看起来您正在代码中创建MediaElement。确保它已添加到 UI。如果它只是被私有字段引用,它将不会播放。然后您可以将LoadedBehavior 设置为“播放”(此时无需调用Play()),或者您需要等待媒体加载后再调用Play()。对于测试,我只使用了Thread.Sleep(),但我希望有一个回调。

    最后但同样重要的是:Uri 构造函数会为您处理大部分 url 编码,但如果您希望 Google 听到“拖放”提示,您需要自己处理 & 字符。

    致谢:这些帖子帮助我找到了这个答案,并可能为您提供更多信息:

    http://social.msdn.microsoft.com/Forums/wpapps/en-US/4baec4b9-451e-4727-a182-555bc312b0bb/using-mediaelement-from-external-source-

    event MediaOpened unable to raised

    【讨论】:

    • 谢谢。我将它添加到 UI 中,并添加了代码以将其作为子项添加到网格中。 MainGrid.Children.Add(myMediaElement) 并且成功了。
    猜你喜欢
    • 1970-01-01
    • 2011-08-29
    • 2014-01-18
    • 2013-04-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    • 1970-01-01
    相关资源
    最近更新 更多