예제 #1
0
            public override async Task <VoiceRespone> Invork(TextRequest textRequest)
            {
                VoiceRespone voiceRespone = new VoiceRespone()
                {
                    Id = textRequest.Id.Value
                };
                var apiSetttings = new SpeechKitClientOptions($"{AppConfig.YandexSpeechApiKey}", "MashaWebApi", Guid.Empty, "server");

                using (var client = new SpeechKitClient(apiSetttings))
                {
                    var options = new SynthesisOptions(textRequest.TextData, 1.1)
                    {
                        AudioFormat = SynthesisAudioFormat.Wav,
                        Language    = _language,
                        Emotion     = Emotion.Good,
                        Quality     = SynthesisQuality.High,
                        Speaker     = Speaker.Omazh
                    };

                    using (var textToSpechResult = await client.TextToSpeechAsync(options, cancellationToken).ConfigureAwait(false))
                    {
                        if (textToSpechResult.TransportStatus != TransportStatus.Ok || textToSpechResult.ResponseCode != HttpStatusCode.OK)
                        {
                            throw new Exception("YandexSpeechKit error: " + textToSpechResult.ResponseCode.ToString());
                        }
                        voiceRespone.VoiceData = textToSpechResult.Result.ToByteArray();
                    }
                }
                return(voiceRespone);
            }
예제 #2
0
        public async System.Threading.Tasks.Task <VoiceMessage> ProcessAsync(TextMessage message)
        {
            switch (message.Language)
            {
            case Core.Enums.Language.English:
                this._language = SynthesisLanguage.English;
                break;

            case Core.Enums.Language.Russian:
                this._language = SynthesisLanguage.Russian;
                break;

            default:
                throw new Exceptions.InvalidMessageException(message.Id, "Invalid Language: " + message.Language.ToString());
            }
            var apiSetttings = new SpeechKitClientOptions($"{YandexCompmnentConfig.YandexSpeechApiKey}", "MashaWebApi", Guid.Empty, "server");

            using (var client = new SpeechKitClient(apiSetttings))
            {
                var options = new SynthesisOptions(message.Text, YandexCompmnentConfig.Speed)
                {
                    AudioFormat = SynthesisAudioFormat.Wav,
                    Language    = _language,
                    Emotion     = Emotion.Good,
                    Quality     = SynthesisQuality.High,
                    Speaker     = Speaker.Omazh
                };

                using (var textToSpechResult = await client.TextToSpeechAsync(options, cancellationToken).ConfigureAwait(false))
                {
                    if (textToSpechResult.TransportStatus != TransportStatus.Ok || textToSpechResult.ResponseCode != HttpStatusCode.OK)
                    {
                        throw new Exception("YandexSpeechKit error: " + textToSpechResult.ResponseCode.ToString());
                    }
                    VoiceMessage result = new VoiceMessage
                    {
                        Id       = message.Id,
                        Language = message.Language,
                        Vioce    = textToSpechResult.Result.ToByteArray()
                    };
                    return(result);
                }
            }
        }