windows - 我无法从 Win32 未打包的应用程序访问 ApplicationData.Current?
问题描述
我的代码:
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()
,但是由于合成音频中的裂缝,我想尝试另一种方法。我需要使用桌面桥吗?而不是Windows.Storage.ApplicationData.Current.LocalFolder
我尝试Windows.Storage.ApplicationData.Current.TemporaryFolder
并得到了同样的例外。
解决方案
Windows.Storage.ApplicationData.Current 仅适用于具有标识的打包应用(UWP 应用和桌面桥应用)。未打包的 Win32 EXE 没有自己隔离应用数据的概念。
目前尚不清楚您为什么需要在这里这样做,或者您要完成什么。这应该与音频播放中的裂缝无关。
推荐阅读
- java - Firebase 未正确发送 otp
- c - 在 C 中用 fgets 覆盖我的数组
- html - 使用锁定的标题使侧边栏滚动?
- go - 如何在 Golang 中获得与solidity `abi.encodePacked` 相同的返回值
- python - 使用 Jupyter 在 PySpark 中来自 Elasticsearch 的数据帧
- php - 无法使用姓名和电子邮件登录
- javascript - 使用 Zajax Wordpress 插件通过 AJAX 加载页面时如何保持 CSS 样式?
- c++ - 无法在链表c ++中附加数据
- html - 是否可以始终打开 HTML5 自动完成列表?
- multithreading - SleepAndRun() 和 ThreadFunc() 在这段代码中做了什么?