【问题标题】:Works in Debug mode but not when publish. How to solve that?在调试模式下工作,但在发布时不工作。如何解决?
【发布时间】:2021-12-18 01:51:43
【问题描述】:

晚上好,

首先,我明确表示我是新手,如果我的问题真的很愚蠢,但我在网上找不到任何答案,我很抱歉。

我正在尝试使用 Azure 资源构建一个带有语音代理的 Web 应用程序。

到目前为止,我有一个使用 ASP.NET 5.0 和语音代理的基本 Web 应用程序。当我在调试中运行应用程序并单击我构建的按钮以激活语音时,它可以工作,您可以听到代理说话。但是,当我在 Chrome 或 edge 上发布应用程序时,即使按钮看起来可以正常工作,也没有声音了,因为在 url 的末尾出现了“?handler=button”。

这是cshtml文件的代码:

@model IndexModel
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

@{
    ViewData["Title"] = "Home page";
}
<div>
    <h1>Hello, world!</h1>
    <p>The time on the server is @DateTime.Now</p>
</div>

<div>
    <h2>Weather Aria</h2>
    <p>
        @Model.Message
    </p>
</div>
<div>
    <form asp-page-handler="button" method="post">
        <button class="btn btn-default">CLICK ME</button>
    </form>
</div>

这里是 Index.cshtml.cs 文件的代码:

using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.CognitiveServices.Speech;
using Microsoft.CognitiveServices.Speech.Audio;


namespace MySecondAzureWebApp.Pages
{
    public class IndexModel : PageModel
    {
        public static async Task SynthesizeAudioAsync()
        {
            //configure subscription: key + location
            var config = SpeechConfig.FromSubscription("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "westeurope");
            using var synthesizer = new SpeechSynthesizer(config);
            await synthesizer.SpeakTextAsync("Hello, I'm Aria, can you hear me ?");
        }

        public string Message { get; private set; } = "Aria starts talking. Can you hear her?";

       public void OnGet()
        {
             Message += $" Server time is { DateTime.Now }";
        }
        public async Task OnPost()
        {
            await SynthesizeAudioAsync();
        }
    }
}

你知道问题出在哪里以及我该如何解决吗?

我在网上看到这可能与服务器有关,但我不知道如何更改它。而且我什至不知道是否是这种情况,因为我只使用 azure。

我将非常感谢任何帮助, 提前致谢。

【问题讨论】:

  • 你能确定你的浏览器标签没有静音吗?
  • 我已经检查过了^^。现在我对代码进行了细微的更改,并且我收到此错误消息“处理您的请求时发生错误。开发模式切换到开发环境会显示有关发生错误的详细信息。不应启用开发环境以进行部署应用程序。它可能导致向最终用户显示来自异常的敏感信息。对于本地调试,通过将 ASPNETCORE_ENVIRONMENT 环境变量设置为 Development 并重新启动应用程序来启用开发环境。"

标签: asp.net azure text-to-speech razor-pages


【解决方案1】:

如果在开发过程中部署到 Azure,则可以在应用程序设置中将 ASPNETCORE_ENVIRONMENT 设置为 Development

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-20
    • 1970-01-01
    • 2018-07-31
    • 1970-01-01
    • 2023-01-11
    • 2022-12-05
    • 1970-01-01
    相关资源
    最近更新 更多