示例#1
0
            public override void Initialize(Enums.Language language)
            {
                switch (language)
                {
                case Enums.Language.English:
                    this._language = SynthesisLanguage.English;
                    break;

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

                default:
                    throw new Exceptions.InvalidLanguageException(language.ToString());
                }
            }
示例#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);
                }
            }
        }