Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 谷歌TTS语音问题_C#_Visual Studio 2012_Windows 8 - Fatal编程技术网

C# 谷歌TTS语音问题

C# 谷歌TTS语音问题,c#,visual-studio-2012,windows-8,C#,Visual Studio 2012,Windows 8,我正在尝试让Google TTS speech正常工作,因为Windows RT/Metro不包含System.speech的定义。下面的代码编译时没有错误,但没有任何内容。我已经调试并检查了“ListBox.SelectedItem”是否包含文本,它确实包含文本 图书馆名称: using System; using System.Collections.Generic; using System.IO; using System.Linq; using Windows.Foundation;

我正在尝试让Google TTS speech正常工作,因为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();
}

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

最后但并非最不重要的一点是:Uri构造函数为您处理大部分url编码,但如果您希望Google Heart说“拖放”,您需要自己处理符号和字符

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


谢谢。我将其添加到UI中,并添加代码将其作为子项添加到网格中
MainGrid.Children.Add(myMediaElement)
成功了。