using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Logging; using Newtonsoft.Json; using SlnMesnac.Common; using SlnMesnac.Config; using SlnMesnac.Model.domain; using SlnMesnac.Redis; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ReadService { public class MessageClient { private readonly RedisHandler _redisHandler; private readonly ILogger _logger; private readonly AppConfig _appConfig; public MessageClient(RedisHandler redisHandler, ILogger logger, IConfiguration configuration) { _redisHandler = redisHandler; _logger = logger; _appConfig = configuration.GetSection("AppConfig").Get(); } public void StartListening() { Console.WriteLine("Redis启动监听朗读声音服务~~~"); _redisHandler.SubscribeToChannel("read_messages", OnMessageReceived); } private async void OnMessageReceived(string channel, string message) { await SpeechStr.Instance.SpeakAsync(message); Console.WriteLine($"客户端朗读消息{message}"); } } }