<分区>
我尝试使用这段代码构建一个测试应用 example
我定义了一个公共(public)类如下:
public class iSpeech
{
// Performs synthesis
public async Task<IRandomAccessStream> SynthesizeTextToSpeechAsync(string text)
{
IRandomAccessStream stream = null;
using (SpeechSynthesizer synthesizer = new SpeechSynthesizer())
{
VoiceInformation voiceInfo =
(
from voice in SpeechSynthesizer.AllVoices
where voice.Gender == VoiceGender.Male
select voice
).FirstOrDefault() ?? SpeechSynthesizer.DefaultVoice;
synthesizer.Voice = voiceInfo;
stream = await synthesizer.SynthesizeTextToStreamAsync(text);
}
return (stream);
}
// Build audio stream
public async Task SpeakTextAsync(string text, MediaElement mediaElement)
{
IRandomAccessStream stream = await this.SynthesizeTextToSpeechAsync(text);
await mediaElement.PlayStreamAsync(stream, true);
}
}
然后我从应用程序主页尝试调用:
public async void btnClick(object sender, RoutedEventArgs e)
{
await iSpeech.SpeakTextAsync("test speech", this.uiMediaElement);
}
我一直在努力
"an object reference is required for the non-static field, method, or Property..." error.
有人可以告诉我我做错了什么吗?