Windows phone 8 背景音频任务中的文本到语音转换
我在WP8.1项目中有一个后台音频任务,它使用Windows phone 8 背景音频任务中的文本到语音转换,windows-phone-8,windows-runtime,windows-phone-8.1,Windows Phone 8,Windows Runtime,Windows Phone 8.1,我在WP8.1项目中有一个后台音频任务,它使用BackgroundMediaPlayer播放音频。 在我的前台应用程序中,我有可以收听的文章(在线文章)。这是通过TTS(语音合成器)完成的 我尝试了两种方法来实现此功能: 在任务中创建SpeechSynthesisStream,并将其与BackgroundMediaPlayer.Current.SetStreamSource(irandomaccesstream)一起使用。 当文本长度超过几百个字符时,始终使用此方法命中内存异常 在前台应用程序
BackgroundMediaPlayer
播放音频。
在我的前台应用程序中,我有可以收听的文章(在线文章)。这是通过TTS(
语音合成器
)完成的
我尝试了两种方法来实现此功能:
SpeechSynthesisStream
,并将其与BackgroundMediaPlayer.Current.SetStreamSource(irandomaccesstream)
一起使用。
当文本长度超过几百个字符时,始终使用此方法命中内存异常
第二次实施的代码:
string content = ".......";
// create stream from synthesizer
SpeechSynthesizer synth = new SpeechSynthesizer();
SpeechSynthesisStream stream = await synth.SynthesizeTextToStreamAsync(content);
// get inputstream and size of stream
ulong size = stream.Size;
IInputStream inputStream = stream.GetInputStreamAt(0);
stream.Dispose();
DataReader dataReader = new DataReader(inputStream);
await dataReader.LoadAsync((uint)size);
byte[] buffer = new byte[(int)size];
dataReader.ReadBytes(buffer);
inputStream.Dispose();
dataReader.Dispose();
// open folder and file
IStorageFolder folder = await ApplicationData.Current.LocalFolder.CreateFolderAsync("Audio", CreationCollisionOption.OpenIfExists);
IStorageFile file = await folder.CreateFileAsync("audio.wav", Windows.Storage.CreationCollisionOption.ReplaceExisting);
// write file
await Windows.Storage.FileIO.WriteBytesAsync(file, buffer);
如何以“内存友好”和快速的方式(不使用在线服务)实现此功能