我在c#和winrt中有:
var stream = await speech.GetSpeakStreamAsync(SpeechText.Text, language);
stream
是Windows.Storage.Streams.IRandomAccessStream
所以我是C#和Winrt的新手。我如何保存此流将WAV文件限制到文件中?预先感谢Basilius
irandomaccessstream具有一种称为getInputStreamat http://msdn.microsoft.com/en-us/library/windows/windows/windows/windows.storage.storage.storage.storeams.irandomaccessstreams.irandomamaccessstream
IInputStream inputStream = stream.GetInputStreamAt(0);
这为您带来了iInputStream。
iInputStream接口仅定义一种方法ReadAsync,它使您可以将字节读取到Ibuffer对象中。Windows.storage.Stream还包括一个基于IInputStream对象创建的DataReader类,然后从流中读取许多.NET对象以及字节数组。http://www.charlespetzold.com/blog/2011/11/080203.html,http://msdn.microsoft.com/library/windows/windows/apps/br208119 >
using (var stream = new InMemoryRandomAccessStream())
{
// for example, render pdf page
var pdfPage = document.GetPage((uint)i);
await pdfPage.RenderToStreamAsync(stream);
// then, write page to file
using (var reader = new DataReader(stream))
{
await reader.LoadAsync((uint)stream.Size);
var buffer = new byte[(int)stream.Size];
reader.ReadBytes(buffer);
await Windows.Storage.FileIO.WriteBytesAsync(file, buffer);
}
}
现在,您有一个包含所有读字节的缓冲区。
您现在可以将此缓冲区保存到文件http://blog.jerrog.jerrog.jerrynixon.com/2012/06/windows-8-how-to-read-files-in-winrt.html
var file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("MyWav.wav", Windows.Storage.CreationCollisionOption.ReplaceExisting);
await Windows.Storage.FileIO.WriteBytesAsync(file, buffer);
我无法将代码添加到注释中,因此这是vb.net中的代码:dim gesprocheneswort作为windows.storage.storeams.irandomaccessstream gesprocheneswort =等待sprich.getSpeakStreamAsync(" das ist ein beispieltext"," de")
Dim Eingabestream As Windows.Storage.Streams.IInputStream = gesprochenesWort.GetInputStreamAt(0)
Dim Datenleser As New Windows.Storage.Streams.DataReader(Eingabestream)
Await Datenleser.LoadAsync(CUInt(gesprochenesWort.Size))
'Dim Dateipuffer As Byte() = New Byte(CInt(gesprochenesWort.Size) - 1) {}
Dim Dateipuffer(gesprochenesWort.Size - 1) As Byte
Datenleser.ReadBytes(Dateipuffer)
Dim Dateiname As String = "MybestWav.wav"
Dim Datei = Await Windows.Storage.KnownFolders.MusicLibrary.CreateFileAsync(Dateiname, Windows.Storage.CreationCollisionOption.ReplaceExisting)
Await Windows.Storage.FileIO.WriteBytesAsync(Datei, Dateipuffer)
;非常感谢您。
最好的问候,basilius