You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB
C#

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<MessageClient> _logger;
private readonly AppConfig _appConfig;
public MessageClient(RedisHandler redisHandler, ILogger<MessageClient> logger, IConfiguration configuration)
{
_redisHandler = redisHandler;
_logger = logger;
_appConfig = configuration.GetSection("AppConfig").Get<AppConfig>();
}
public void StartListening()
{
1 month ago
Console.WriteLine("启动监听朗读声音服务~~~");
_redisHandler.SubscribeToChannel("read_messages", OnMessageReceived);
}
private async void OnMessageReceived(string channel, string message)
{
1 month ago
await SpeechStr.Instance.SpeakAsync(message);
Console.WriteLine($"客户端朗读消息{message}");
}
}
}