私はc#とwinrtにあります:
var stream = await speech.GetSpeakStreamAsync(SpeechText.Text, language);
stream
は Windows.Storage.Streams.IRandomAccessStream
だから私はc#とwinrtに完全に慣れていません。このストリームにwavファイルが含まれているファイルをファイルに保存するにはどうすればよいですか?よろしくお願いします、バシリウス
私はc#とwinrtにあります:
var stream = await speech.GetSpeakStreamAsync(SpeechText.Text, language);
stream
は Windows.Storage.Streams.IRandomAccessStream
だから私はc#とwinrtに完全に慣れていません。このストリームにwavファイルが含まれているファイルをファイルに保存するにはどうすればよいですか?よろしくお願いします、バシリウス
IRandomAccessStreamには、GetInputStreamAthttp://msdn.microsoft.com/en-US/library/windows/apps/windows.storage.streams.irandomaccessstreamというメソッドがあります。
IInputStream inputStream = stream.GetInputStreamAt(0);
これにより、IInputStreamが取得されます。
IInputStreamインターフェイスは、バイトをIBufferオブジェクトに読み込むことができるReadAsyncという1つのメソッドのみを定義します。Windows.Storage.Streamには、IInputStreamオブジェクトに基づいて作成し、ストリームおよびバイト配列から多数の.NETオブジェクトを読み取るDataReaderクラスも含まれています。http://www.charlespetzold.com/blog/2011/11/080203.html、http://msdn.microsoft.com/library/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.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のコードは次のとおりです。DimgesprochenesWort As Windows.Storage.Streams.IRandomAccessStream gesprochenesWort = Await 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)
;ありがとうございます。
よろしく、バシリウス