// This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { FFmpegUtil.InitFFmpeg(); services.AddDbContext <TencentCloudDbContext>(option => option.UseMySql(Configuration.GetConnectionString("Mysql"))); services.AddScoped <WeixinInteractionServer>(); services.AddHttpContextAccessor(); services.AddMvc(); services.AddMemoryCache(); //使用本地缓存必须添加 services.AddSession(); //使用Session /* * CO2NET 是从 Senparc.Weixin 分离的底层公共基础模块,经过了长达 6 年的迭代优化,稳定可靠。 * 关于 CO2NET 在所有项目中的通用设置可参考 CO2NET 的 Sample: * https://github.com/Senparc/Senparc.CO2NET/blob/master/Sample/Senparc.CO2NET.Sample.netcore/Startup.cs */ services.AddSenparcGlobalServices(Configuration) //Senparc.CO2NET 全局注册 .AddSenparcWeixinServices(Configuration); //Senparc.Weixin 注册 }
/// <summary> /// 处理语音请求 /// </summary> /// <param name="requestMessage"></param> /// <returns></returns> public override IResponseMessageBase OnVoiceRequest(RequestMessageVoice requestMessage) { var responseMessage = CreateResponseMessage <ResponseMessageText>(); var path = MediaApi.Get(appId, requestMessage.MediaId, $"{Server.AppDomainAppPath}App_Data/Audio/"); var outPutPath = $"{path.Substring(0, path.Length - 4)}.mp3"; var success = FFmpegUtil.Arm2Mp3Async(path, outPutPath).ConfigureAwait(false).GetAwaiter().GetResult(); if (success) { var intelligentVoiceServer = new IntelligentVoiceServer(); var text = intelligentVoiceServer.Voice2Text(outPutPath).ConfigureAwait(false).GetAwaiter().GetResult(); responseMessage.Content = text; File.Delete(path); File.Delete(outPutPath); } else { File.Delete(path); responseMessage.Content = "转换失败"; } return(responseMessage); }