Я не могу получить доступ к ApplicationData.Current из распакованного приложения Win32? - PullRequest
0 голосов
/ 26 апреля 2019

Мой код:

using System;
using Windows;

namespace SampleSynthesis {
  class Program {
    static async System.Threading.Tasks.Task Main(string[] args) {

      var synth = new Windows.Media.SpeechSynthesis.SpeechSynthesizer();
      Windows.Media.SpeechSynthesis.SpeechSynthesisStream stream =
          await synth.SynthesizeTextToStreamAsync("I want to listen to this text");

      using (var reader = new Windows.Storage.Streams.DataReader(stream)) {
          await reader.LoadAsync((uint)stream.Size);
          Windows.Storage.Streams.IBuffer buffer = reader.ReadBuffer((uint)stream.Size);
          Windows.Storage.StorageFile file = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync("audio.wav");
          await Windows.Storage.FileIO.WriteBufferAsync(file, buffer);
    }
  }
}

Скомпилировано с этой командой:

"C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\Roslyn\csc.exe" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.Speech.dll","C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll","C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.runtime.dll","C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.17763.0\Windows.winmd","C:\Windows\Microsoft.NET\Framework64\v4.0.30319\System.Threading.Tasks.dll" tts.cs

Я получаю:

Unhandled Exception: System.InvalidOperationException: The process has no package identity. (Exception from HRESULT: 0x80073D54)
   at Windows.Storage.ApplicationData.get_Current()
   at SampleSynthesis.Program.<Main>d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
   at SampleSynthesis.Program.<Main>(String[] args)

Может быть, существует другой способ сохранить WAV?Я знаю, что могу использовать более простой SetOutputToWaveFile(), но из-за трещин в синтезированном аудио я хочу попробовать другой метод.Мне нужно использовать Desktop Bridge?Вместо Windows.Storage.ApplicationData.Current.LocalFolder я попытался Windows.Storage.ApplicationData.Current.TemporaryFolder и получил то же исключение.

1 Ответ

2 голосов
/ 27 апреля 2019

Windows.Storage.ApplicationData.Current применяется только к упакованным приложениям, которые имеют идентичность (приложения UWP и приложения Desktop Bridge).Unpackaged Win32 EXE не имеет понятия о своих собственных изолированных данных приложения.

Не ясно, зачем вам это здесь или что вы пытаетесь достичь.Это не должно иметь ничего общего с трещинами при воспроизведении аудио.

...