Esempio n. 1
0
        public byte[] UploadVoice(string engText)
        {
            string          apiKey      = "6319e58e8ef743e39bfca3a49bb1a3ec";
            bool            isSSL       = false;
            string          text        = engText;
            string          lang        = Languages.English_UnitedStates;
            VoiceParameters voiceParams = new VoiceParameters(text, lang)
            {
                AudioCodec  = AudioCodec.MP3,
                AudioFormat = AudioFormat.Format_44KHZ.AF_44khz_16bit_stereo,
                IsBase64    = false,
                IsSsml      = false,
                SpeedRate   = 0
            };
            VoiceProvider voiceProvider = new VoiceProvider(apiKey, isSSL);

            byte[] voice = new byte[0];
            try
            {
                voice = voiceProvider.Speech <byte[]>(voiceParams);
            }
            catch (Exception ex) {
#if DEBUG
                Debug.WriteLine(ex.Message);
#endif
            }
            return(voice);
        }
Esempio n. 2
0
        public async Task <YandexTtsResponse> InvokeAsync(string text, bool ssml, VoiceParameters voice, FormatParameters format, CancellationToken cancellationToken = default)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                throw new ArgumentNullException(nameof(text));
            }
            if (voice == null)
            {
                throw new ArgumentNullException(nameof(voice));
            }
            if (format == null)
            {
                throw new ArgumentNullException(nameof(format));
            }

            var options = new InvokeOptions()
            {
                AudioFormat = format,
                Voice       = voice,
                SSML        = ssml,
                Text        = text
            };

            return(await InvokeAsync(options, cancellationToken));
        }
Esempio n. 3
0
        public override bool Start(VoiceParameters voiceparams)
        {
            int note = keyOverride > -1 ? keyOverride : voiceparams.note;
            int vel  = velOverride > -1 ? velOverride : voiceparams.velocity;

            //setup generator
            voiceparams.generatorParams[0].QuickSetup(voiceparams.generators[0]);
            //setup envelopes
            voiceparams.envelopes[0].QuickSetup(voiceparams.synth.SampleRate, note, keynumToModEnvHold, keynumToModEnvDecay, 1, this.EnvelopeInfo[0]);
            float susMod = (float)SynthHelper.DBtoLinear(-sustainVolEnv);

            if (susMod <= 1e-5f)
            {
                susMod = 0;
            }
            voiceparams.envelopes[1].QuickSetup(voiceparams.synth.SampleRate, note, keynumToVolEnvHold, keynumToVolEnvDecay, susMod, this.EnvelopeInfo[1]);
            //setup filter
            //if (filterQ == 1 && modLfoToFilterFc + modEnvToFilterFc + iniFilterFc > 14000)
            voiceparams.filters[0].Disable();
            //else
            //    voiceparams.filters[0].QuickSetup(44100, note, 1f, this.FilterInfo[0]);
            //setup lfos
            voiceparams.lfos[0].QuickSetup(voiceparams.synth.SampleRate, LfoInfo[0]);
            voiceparams.lfos[1].QuickSetup(voiceparams.synth.SampleRate, LfoInfo[1]);
            //calculate base volume and pitch
            voiceparams.pitchOffset = (note - voiceparams.generators[0].RootKey) * voiceparams.generators[0].KeyTrack + voiceparams.generators[0].Tune;
            voiceparams.volOffset   = -20.0f * (float)Math.Log10(16129.0 / (vel * vel)) + -initialAttn;
            //check if we have finished before we have begun
            return(voiceparams.generatorParams[0].currentState != GeneratorStateEnum.Finished && voiceparams.envelopes[1].CurrentState != EnvelopeStateEnum.None);
        }
Esempio n. 4
0
        public override bool Start(VoiceParameters voiceparams)
        {
            int note = keyOverride > -1 ? keyOverride : voiceparams.note;
            int vel  = velOverride > -1 ? velOverride : voiceparams.velocity;

            //setup generator
            voiceparams.generatorParams[0].QuickSetup(gen);
            //setup envelopes
            voiceparams.envelopes[0].QuickSetupSf2(voiceparams.synthParams.synth.SampleRate, note, keynumToModEnvHold, keynumToModEnvDecay, false, mod_env);
            voiceparams.envelopes[1].QuickSetupSf2(voiceparams.synthParams.synth.SampleRate, note, keynumToVolEnvHold, keynumToVolEnvDecay, true, vel_env);
            //setup filter
            //voiceparams.pData[0].int1 = iniFilterFc - (int)(2400 * CalculateModulator(SourceTypeEnum.Linear, TransformEnum.Linear, DirectionEnum.MaxToMin, PolarityEnum.Unipolar, voiceparams.velocity, 0, 127));
            //if (iniFilterFc >= 13500 && fltr.Resonance <= 1)
            voiceparams.filters[0].Disable();
            //else
            //    voiceparams.filters[0].QuickSetup(voiceparams.synthParams.synth.SampleRate, note, 1f, fltr);
            //setup lfos
            voiceparams.lfos[0].QuickSetup(voiceparams.synthParams.synth.SampleRate, mod_lfo);
            voiceparams.lfos[1].QuickSetup(voiceparams.synthParams.synth.SampleRate, vib_lfo);
            //calculate initial pitch
            voiceparams.pitchOffset  = (note - gen.RootKey) * gen.KeyTrack + gen.Tune;
            voiceparams.pitchOffset += (int)(100.0 * (voiceparams.synthParams.masterCoarseTune + (voiceparams.synthParams.masterFineTune.Combined - 8192.0) / 8192.0));
            //calculate initial volume
            voiceparams.volOffset  = initialAttn;
            voiceparams.volOffset -= 96.0f * (float)CalculateModulator(SourceTypeEnum.Concave, TransformEnum.Linear, DirectionEnum.MaxToMin, PolarityEnum.Unipolar, voiceparams.velocity, 0, 127);
            voiceparams.volOffset -= 96.0f * (float)CalculateModulator(SourceTypeEnum.Concave, TransformEnum.Linear, DirectionEnum.MaxToMin, PolarityEnum.Unipolar, voiceparams.synthParams.volume.Coarse, 0, 127);
            //check if we have finished before we have begun
            return(voiceparams.generatorParams[0].currentState != GeneratorStateEnum.Finished && voiceparams.envelopes[1].CurrentState != EnvelopeStateEnum.None);
        }
Esempio n. 5
0
        public override bool Start(VoiceParameters voiceparams)
        {
            //calculate velocity
            float fVel = voiceparams.velocity / 127f;

            //setup generator
            voiceparams.generatorParams[0].QuickSetup(voiceparams.generators[0]);
            //setup envelopes
            voiceparams.envelopes[0].QuickSetup(voiceparams.synth.SampleRate, fVel, this.EnvelopeInfo[0]);
            voiceparams.envelopes[1].QuickSetup(voiceparams.synth.SampleRate, fVel, this.EnvelopeInfo[1]);
            voiceparams.envelopes[2].QuickSetup(voiceparams.synth.SampleRate, fVel, this.EnvelopeInfo[2]);
            //setup lfos
            voiceparams.lfos[0].QuickSetup(voiceparams.synth.SampleRate, LfoInfo[0]);
            voiceparams.lfos[1].QuickSetup(voiceparams.synth.SampleRate, LfoInfo[1]);
            voiceparams.lfos[2].QuickSetup(voiceparams.synth.SampleRate, LfoInfo[2]);
            //setup filter
            voiceparams.filters[0].QuickSetup(voiceparams.synth.SampleRate, voiceparams.note, fVel, this.FilterInfo[0]);
            if (!voiceparams.filters[0].Enabled)
            {//disable filter components if necessary
                voiceparams.envelopes[1].Depth = 0f;
                voiceparams.lfos[1].Depth      = 0f;
            }
            //setup sfz params
            voiceparams.pitchOffset = (voiceparams.note - voiceparams.generators[0].RootKey) * voiceparams.generators[0].KeyTrack + (int)(fVel * voiceparams.generators[0].VelocityTrack) + voiceparams.generators[0].Tune;
            float dBVel = -20.0f * (float)Math.Log10(16129.0 / (voiceparams.velocity * voiceparams.velocity));

            voiceparams.volOffset = (float)SynthHelper.DBtoLinear((voiceparams.note - ampRootKey) * ampKeyTrack + dBVel * ampVelTrack + sfzVolume) * voiceparams.synth.MixGain;
            //check if we have finished before we have begun
            return(voiceparams.generatorParams[0].currentState != GeneratorStateEnum.Finished && voiceparams.envelopes[2].CurrentState != EnvelopeStateEnum.None);
        }
Esempio n. 6
0
 public override void Stop(VoiceParameters voiceparams)
 {
     voiceparams.generators[0].Release(voiceparams.generatorParams[0]);
     if (voiceparams.generators[0].LoopMode != LoopModeEnum.OneShot)
     {
         voiceparams.envelopes[0].Release();
     }
 }
Esempio n. 7
0
 public override void Stop(VoiceParameters voiceparams)
 {
     gen.Release(voiceparams.generatorParams[0]);
     if (gen.LoopMode != LoopModeEnum.OneShot)
     {
         voiceparams.envelopes[0].Release(Synthesis.Synthesizer.NonAudible);
     }
 }
Esempio n. 8
0
        public override void Process(VoiceParameters voiceparams, int startIndex, int endIndex, bool isMuted)
        {
            //--Base pitch calculation
            var basePitchFrequency = SynthHelper.CentsToPitch(voiceparams.SynthParams.CurrentPitch) * gen.Frequency;
            var pitchWithBend      = basePitchFrequency * SynthHelper.CentsToPitch(voiceparams.PitchOffset);
            var basePitch          = pitchWithBend / voiceparams.SynthParams.Synth.SampleRate;

            float baseVolume = isMuted ? 0 : voiceparams.SynthParams.Synth.MasterVolume * voiceparams.SynthParams.CurrentVolume * SynthConstants.DefaultMixGain * voiceparams.SynthParams.MixVolume;

            //--Main Loop
            for (int x = startIndex; x < endIndex; x += SynthConstants.DefaultBlockSize * SynthConstants.AudioChannels)
            {
                voiceparams.Envelopes[0].Increment(SynthConstants.DefaultBlockSize);
                voiceparams.Envelopes[1].Increment(SynthConstants.DefaultBlockSize);
                voiceparams.Lfos[0].Increment(SynthConstants.DefaultBlockSize);
                voiceparams.Lfos[1].Increment(SynthConstants.DefaultBlockSize);
                //--Calculate pitch and get next block of samples
                gen.GetValues(voiceparams.GeneratorParams[0], voiceparams.BlockBuffer, basePitch *
                              SynthHelper.CentsToPitch((int)(voiceparams.Envelopes[0].Value * modEnvToPitch +
                                                             voiceparams.Lfos[0].Value * modLfoToPitch + voiceparams.Lfos[1].Value * vibLfoToPitch)));
                //--Filter
                if (voiceparams.Filters[0].Enabled)
                {
                    double centsFc = voiceparams.PData[0].Int1 + voiceparams.Lfos[0].Value * modLfoToFilterFc + voiceparams.Envelopes[0].Value * modEnvToFilterFc;
                    if (centsFc > 13500)
                    {
                        centsFc = 13500;
                    }
                    voiceparams.Filters[0].CutOff = SynthHelper.KeyToFrequency(centsFc / 100.0, 69);
                    if (voiceparams.Filters[0].CoeffNeedsUpdating)
                    {
                        voiceparams.Filters[0].ApplyFilterInterp(voiceparams.BlockBuffer, voiceparams.SynthParams.Synth.SampleRate);
                    }
                    else
                    {
                        voiceparams.Filters[0].ApplyFilter(voiceparams.BlockBuffer);
                    }
                }
                //--Volume calculation
                float volume = (float)SynthHelper.DBtoLinear(voiceparams.VolOffset + voiceparams.Envelopes[1].Value + voiceparams.Lfos[0].Value * modLfoToVolume) * baseVolume;

                //--Mix block based on number of channels
                if (SynthConstants.AudioChannels == 2)
                {
                    voiceparams.MixMonoToStereoInterp(x, volume * pan.Left * voiceparams.SynthParams.CurrentPan.Left, volume * pan.Right * voiceparams.SynthParams.CurrentPan.Right);
                }
                else
                {
                    voiceparams.MixMonoToMonoInterp(x, volume);
                }
                //--Check and end early if necessary
                if ((voiceparams.Envelopes[1].CurrentStage > EnvelopeState.Hold && volume <= SynthConstants.NonAudible) || voiceparams.GeneratorParams[0].CurrentState == GeneratorState.Finished)
                {
                    voiceparams.State = VoiceStateEnum.Stopped;
                    return;
                }
            }
        }
Esempio n. 9
0
 public override void Stop(VoiceParameters voiceparams)
 {
     gen.Release(voiceparams.GeneratorParams[0]);
     if (gen.LoopMode != LoopMode.OneShot)
     {
         voiceparams.Envelopes[0].Release(SynthConstants.DenormLimit);
         voiceparams.Envelopes[1].ReleaseSf2VolumeEnvelope();
     }
 }
Esempio n. 10
0
 public override void Stop(VoiceParameters voiceparams)
 {
     gen.Release(voiceparams.generatorParams[0]);
     if (gen.LoopMode != LoopModeEnum.OneShot)
     {
         voiceparams.envelopes[0].Release(Synthesis.Synthesizer.DenormLimit);
         voiceparams.envelopes[1].ReleaseSf2VolumeEnvelope();
     }
 }
Esempio n. 11
0
        public override void Process(VoiceParameters voiceparams, int startIndex, int endIndex)
        {
            //--Base pitch calculation
            double basePitch = SynthHelper.CentsToPitch(voiceparams.pitchOffset + voiceparams.synth.totalPitch[voiceparams.channel])
                               * voiceparams.generators[0].Frequency / voiceparams.synth.SampleRate;

            //--Base volume calculation
            //float baseVolume = voiceparams.volOffset * voiceparams.synth.totalVolume[voiceparams.channel];
            //--Main Loop
            for (int x = startIndex; x < endIndex; x += Synthesizer.DefaultBlockSize * voiceparams.synth.AudioChannels)
            {
                voiceparams.envelopes[0].Increment(Synthesizer.DefaultBlockSize);
                voiceparams.envelopes[1].Increment(Synthesizer.DefaultBlockSize);
                voiceparams.lfos[0].Increment(Synthesizer.DefaultBlockSize);
                voiceparams.lfos[1].Increment(Synthesizer.DefaultBlockSize);

                //--Calculate pitch and get next block of samples
                voiceparams.generators[0].GetValues(voiceparams.generatorParams[0], voiceparams.blockBuffer, basePitch *
                                                    SynthHelper.CentsToPitch((int)(voiceparams.envelopes[0].Value * modEnvToPitch +
                                                                                   voiceparams.lfos[0].Value * modLfoToPitch + voiceparams.lfos[1].Value * vibLfoToPitch)));
                //--Filter
                if (voiceparams.filters[0].Enabled)
                {
                    double centsFc = iniFilterFc + voiceparams.lfos[0].Value * modLfoToFilterFc + voiceparams.envelopes[0].Value * modEnvToFilterFc;
                    if (centsFc > 13500)
                    {
                        centsFc = 13500;
                    }
                    voiceparams.filters[0].UpdateCoefficients(SynthHelper.KeyToFrequency(centsFc / 100.0, 69) / voiceparams.synth.SampleRate, filterQ);
                    voiceparams.filters[0].ApplyFilter(voiceparams.blockBuffer);
                }
                //--Volume calculation
                float volume = (float)SynthHelper.DBtoLinear(voiceparams.volOffset + voiceparams.lfos[0].Value * modLfoToVolume) * voiceparams.envelopes[1].Value * voiceparams.synth.totalVolume[voiceparams.channel] * voiceparams.synth.MixGain;
                //--Mix block based on number of channels
                if (voiceparams.synth.AudioChannels == 2)
                {
                    SynthHelper.MixMonoToStereoInterpolation(x,
                                                             volume * pan.Left * voiceparams.synth.panPositions[voiceparams.channel].Left,
                                                             volume * pan.Right * voiceparams.synth.panPositions[voiceparams.channel].Right,
                                                             voiceparams);
                }
                else
                {
                    SynthHelper.MixMonoToMonoInterpolation(x, volume, voiceparams);
                }
                //--Check and end early if necessary
                if ((voiceparams.envelopes[1].CurrentState > EnvelopeStateEnum.Hold && volume <= Synthesizer.NonAudible) || voiceparams.generatorParams[0].currentState == GeneratorStateEnum.Finished)
                {
                    voiceparams.state = VoiceStateEnum.Stopped;
                    return;
                }
            }
        }
Esempio n. 12
0
        private float GetAmplitude(VoiceParameters vp)
        {
            var data = vp.blockBuffer;
            var max  = 0F;

            for (var t = 0; t < data.Length; t++)
            {
                var a = data[t] > 0 ? data[t] : -data[t];
                if (a > max)
                {
                    max = a;
                }
            }
            return(max);
        }
Esempio n. 13
0
        public override void Process(VoiceParameters voiceparams, int startIndex, int endIndex)
        {
            //--Base pitch calculation
            double basePitch = SynthHelper.CentsToPitch(voiceparams.pitchOffset + voiceparams.synthParams.currentPitch)
                               * gen.Period * gen.Frequency / voiceparams.synthParams.synth.SampleRate;
            //--Base volume calculation
            float baseVolume = voiceparams.volOffset * voiceparams.synthParams.currentVolume;

            //--Main Loop
            for (int x = startIndex; x < endIndex; x += Synthesizer.DefaultBlockSize * voiceparams.synthParams.synth.AudioChannels)
            {
                //--Volume Envelope
                voiceparams.envelopes[0].Increment(Synthesizer.DefaultBlockSize);
                //--Lfo pitch modulation
                double pitchMod;
                if (voiceparams.synthParams.modRange.Combined != 0)
                {
                    voiceparams.lfos[0].Increment(Synthesizer.DefaultBlockSize);
                    pitchMod = SynthHelper.CentsToPitch((int)(voiceparams.lfos[0].Value * voiceparams.synthParams.currentMod));
                }
                else
                {
                    pitchMod = 1;
                }
                //--Get next block of samples
                gen.GetValues(voiceparams.generatorParams[0], voiceparams.blockBuffer, basePitch * pitchMod);
                //--Mix block based on number of channels
                float volume = baseVolume * voiceparams.envelopes[0].Value;
                if (voiceparams.synthParams.synth.AudioChannels == 2)
                {
                    voiceparams.MixMonoToStereoInterp(x,
                                                      volume * voiceparams.synthParams.currentPan.Left,
                                                      volume * voiceparams.synthParams.currentPan.Right);
                }
                else
                {
                    voiceparams.MixMonoToMonoInterp(x, volume);
                }
                //--Check and end early if necessary
                if (voiceparams.envelopes[0].CurrentState == EnvelopeStateEnum.None || voiceparams.generatorParams[0].currentState == GeneratorStateEnum.Finished)
                {
                    voiceparams.state = VoiceStateEnum.Stopped;
                    return;
                }
            }
        }
        public static void AddVoiceParam(IRequestContext context, VoiceParameters voice)
        {
            if (voice == null || !voice.IsSetParam())
            {
                throw new ArgumentException(nameof(voice));
            }

            context.AddParametr("lang", voice.Language);
            context.AddParametr("voice", voice.Name);
            if (!string.IsNullOrWhiteSpace(voice.Emotion))
            {
                context.AddParametr("emotion", voice.Emotion);
            }
            if (!string.IsNullOrWhiteSpace(voice.Emotion))
            {
                context.AddParametr("speed", voice.Speed);
            }
        }
Esempio n. 15
0
        public override bool Start(VoiceParameters voiceparams)
        {
            //calculate velocity
            float fVel = voiceparams.velocity / 127f;

            //reset generator
            voiceparams.generatorParams[0].QuickSetup(voiceparams.generators[0]);
            //reset envelope
            voiceparams.envelopes[0].QuickSetup(voiceparams.synth.SampleRate, fVel, EnvelopeInfo[0]);
            //reset lfo (vibra)
            voiceparams.lfos[0].QuickSetup(voiceparams.synth.SampleRate, LfoInfo[0]);
            //calculate initial pitch
            voiceparams.pitchOffset = (voiceparams.note - voiceparams.generators[0].RootKey) * voiceparams.generators[0].KeyTrack + (int)(fVel * voiceparams.generators[0].VelocityTrack) + voiceparams.generators[0].Tune;
            //calculate initial volume
            voiceparams.volOffset = fVel * voiceparams.synth.MixGain;
            //check if we have finished before we have begun
            return(voiceparams.generatorParams[0].currentState != GeneratorStateEnum.Finished && voiceparams.envelopes[2].CurrentState != EnvelopeStateEnum.None);
        }
Esempio n. 16
0
        static async Task <byte[]> GetSpeach(string text)
        {
            var apiKey = "0d3463c92d324c5599d1fa96e0012a47";
            var isSSL  = false;
            var lang   = Languages.Russian;

            var voiceParams = new VoiceParameters(text, lang)
            {
                AudioCodec  = AudioCodec.MP3,
                AudioFormat = AudioFormat.Format_44KHZ.AF_44khz_16bit_stereo,
                IsBase64    = false,
                IsSsml      = false,
                SpeedRate   = 0
            };

            var voiceProvider = new VoiceProvider(apiKey, isSSL);
            var voice         = await voiceProvider.SpeechTaskAsync <byte[]>(voiceParams);

            return(voice);
        }
Esempio n. 17
0
        public override bool Start(VoiceParameters voiceparams)
        {
            //calculate velocity
            float fVel = voiceparams.velocity / 127f;

            //reset generator
            voiceparams.generatorParams[0].QuickSetup(gen);
            //reset envelope
            voiceparams.envelopes[0].QuickSetup(voiceparams.synthParams.synth.SampleRate, fVel, env);
            //reset lfo (vibra)
            voiceparams.lfos[0].QuickSetup(voiceparams.synthParams.synth.SampleRate, lfo);
            //calculate initial pitch
            voiceparams.pitchOffset  = (voiceparams.note - gen.RootKey) * gen.KeyTrack + (int)(fVel * gen.VelocityTrack) + gen.Tune;
            voiceparams.pitchOffset += (int)(100.0 * (voiceparams.synthParams.masterCoarseTune + (voiceparams.synthParams.masterFineTune.Combined - 8192.0) / 8192.0));
            //calculate initial volume
            voiceparams.volOffset  = voiceparams.synthParams.volume.Combined / 16383f;
            voiceparams.volOffset *= voiceparams.volOffset * fVel * voiceparams.synthParams.synth.MixGain;
            //check if we have finished before we have begun
            return(voiceparams.generatorParams[0].currentState != GeneratorStateEnum.Finished && voiceparams.envelopes[0].CurrentState != EnvelopeStateEnum.None);
        }
Esempio n. 18
0
        public override bool Start(VoiceParameters voiceparams)
        {
            //calculate velocity
            float fVel = voiceparams.velocity / 127f;

            //reset counters
            voiceparams.counters[0] = voiceparams.generators[0].LoopStartPhase;
            voiceparams.counters[1] = voiceparams.generators[1].LoopStartPhase;
            voiceparams.counters[2] = 0.0;
            //reset envelopes
            voiceparams.envelopes[0].QuickSetup(voiceparams.synth.SampleRate, fVel, EnvelopeInfo[0]);
            voiceparams.envelopes[1].QuickSetup(voiceparams.synth.SampleRate, fVel, EnvelopeInfo[1]);
            //reset lfo (vibra)
            voiceparams.lfos[0].QuickSetup(voiceparams.synth.SampleRate, LfoInfo[0]);
            //calc initial volume
            float dBVel = -20.0f * (float)Math.Log10(16129.0 / (voiceparams.velocity * voiceparams.velocity));

            voiceparams.volOffset = (float)SynthHelper.DBtoLinear(dBVel) * voiceparams.synth.MixGain;
            //check if we have finished before we have begun
            return(voiceparams.envelopes[0].CurrentState != EnvelopeStateEnum.None);
        }
Esempio n. 19
0
    public void TextToSpeech(string text)
    {
        Debug.Log(text);
        var apiKey = "ADD VOICERSS KEY HERE";
        var isSSL  = false;
        var lang   = Languages.English_GreatBritain;

        var voiceParams = new VoiceParameters(text, lang)
        {
            AudioCodec  = AudioCodec.WAV,
            AudioFormat = AudioFormat.Format_44KHZ.AF_44khz_16bit_stereo,
            IsBase64    = false,
            IsSsml      = false,
            SpeedRate   = 0
        };

        var voiceProvider = new VoiceProvider(apiKey, isSSL);
        var voice         = voiceProvider.Speech <byte[]>(voiceParams);

        PrintReply.Audio = voice;
    }
Esempio n. 20
0
        public void Say(string text, string lang)
        {
            var voiceParams = new VoiceParameters(text, lang)
            {
                AudioCodec  = AudioCodec.MP3,
                AudioFormat = AudioFormat.Format_44KHZ.AF_44khz_16bit_mono,
                IsBase64    = false,
                IsSsml      = false,
                SpeedRate   = SpeedRate
            };

            _filePath = GetFilePath(text);
            if (!File.Exists(_filePath))
            {
                _voiceProvider.SpeechAsync <byte[]>(voiceParams);
            }
            else
            {
                Mp3Player.PlayFile(_filePath);
            }
        }
Esempio n. 21
0
        public static void GetData(string Text)
        {
            var apiKey = "8251658e18e14a7eb81d4366a62ee4bf";
            var isSSL  = false;
            var lang   = Languages.English_UnitedStates;

            var voiceParams = new VoiceParameters(Text, lang)
            {
                AudioCodec  = AudioCodec.MP3,
                AudioFormat = AudioFormat.Format_44KHZ.AF_44khz_16bit_stereo,
                IsBase64    = false,
                IsSsml      = false,
                SpeedRate   = 0
            };


            var voiceProvider = new VoiceProvider(apiKey, isSSL);
            var voice         = voiceProvider.Speech <byte[]>(voiceParams);
            var fileName      = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "voice.mp3");

            File.WriteAllBytes(fileName, voice);
        }
Esempio n. 22
0
        public override bool Start(VoiceParameters voiceparams)
        {
            //calculate velocity
            float fVel = voiceparams.velocity / 127f;

            //reset counters
            voiceparams.pData[0].double1 = cGen.LoopStartPhase;
            voiceparams.pData[1].double1 = mGen.LoopStartPhase;
            voiceparams.pData[2].double1 = 0.0;
            //reset envelopes
            voiceparams.envelopes[0].QuickSetup(voiceparams.synthParams.synth.SampleRate, fVel, cEnv);
            voiceparams.envelopes[1].QuickSetup(voiceparams.synthParams.synth.SampleRate, fVel, mEnv);
            //reset lfo (vibra)
            voiceparams.lfos[0].QuickSetup(voiceparams.synthParams.synth.SampleRate, lfo);
            //calculate initial pitch
            voiceparams.pitchOffset = (int)(100.0 * (voiceparams.synthParams.masterCoarseTune + (voiceparams.synthParams.masterFineTune.Combined - 8192.0) / 8192.0));
            //calc initial volume
            voiceparams.volOffset  = voiceparams.synthParams.volume.Combined / 16383f;
            voiceparams.volOffset *= voiceparams.volOffset * fVel * voiceparams.synthParams.synth.MixGain;
            //check if we have finished before we have begun
            return(voiceparams.envelopes[0].CurrentState != EnvelopeStateEnum.None);
        }
Esempio n. 23
0
        public byte[] Get(string text)
        {
            var apiKey = "c2e4f726d17e459796706e2436d73806";
            var isSSL  = false;
            var lang   = Languages.English_UnitedStates;

            var voiceParams = new VoiceParameters(text, lang)
            {
                AudioCodec  = AudioCodec.MP3,
                AudioFormat = AudioFormat.Format_44KHZ.AF_44khz_16bit_stereo,
                IsBase64    = false,
                IsSsml      = false,
                SpeedRate   = 0
            };

            var voiceProvider = new VoiceProvider(apiKey, isSSL);
            var voice         = voiceProvider.Speech <byte[]>(voiceParams);
            //To convert byte array to file
            var fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "voice.mp3");

            System.IO.File.WriteAllBytes(fileName, voice);
            return(voiceProvider.Speech <byte[]>(voiceParams));
        }
Esempio n. 24
0
        public override bool Start(VoiceParameters voiceparams)
        {
            //calculate velocity
            float fVel = voiceparams.velocity / 127f;

            //setup generator
            voiceparams.generatorParams[0].QuickSetup(gen);
            //setup envelopes
            voiceparams.envelopes[0].QuickSetup(voiceparams.synthParams.synth.SampleRate, fVel, ptch_env);
            voiceparams.envelopes[1].QuickSetup(voiceparams.synthParams.synth.SampleRate, fVel, fltr_env);
            voiceparams.envelopes[2].QuickSetup(voiceparams.synthParams.synth.SampleRate, fVel, amp_env);
            //setup lfos
            voiceparams.lfos[0].QuickSetup(voiceparams.synthParams.synth.SampleRate, ptch_lfo);
            voiceparams.lfos[1].QuickSetup(voiceparams.synthParams.synth.SampleRate, fltr_lfo);
            voiceparams.lfos[2].QuickSetup(voiceparams.synthParams.synth.SampleRate, amp_lfo);
            //setup filter
            voiceparams.filters[0].QuickSetup(voiceparams.synthParams.synth.SampleRate, voiceparams.note, fVel, fltr);
            voiceparams.pData[0].double1 = voiceparams.filters[0].Cutoff;
            if (!voiceparams.filters[0].Enabled)
            {//disable filter components if necessary
                voiceparams.envelopes[1].Depth = 0f;
                voiceparams.lfos[1].Depth      = 0f;
            }
            //setup sfz params
            //calculate initial pitch
            voiceparams.pitchOffset  = (voiceparams.note - gen.RootKey) * gen.KeyTrack + (int)(fVel * gen.VelocityTrack) + gen.Tune;
            voiceparams.pitchOffset += (int)(100.0 * (voiceparams.synthParams.masterCoarseTune + (voiceparams.synthParams.masterFineTune.Combined - 8192.0) / 8192.0));
            //calculate initial vol
            voiceparams.volOffset  = voiceparams.synthParams.volume.Combined / 16383f;
            voiceparams.volOffset *= voiceparams.volOffset * voiceparams.synthParams.synth.MixGain;
            float dBVel = -20.0f * (float)Math.Log10(16129.0 / (voiceparams.velocity * voiceparams.velocity));

            voiceparams.volOffset *= (float)SynthHelper.DBtoLinear((voiceparams.note - ampRootKey) * ampKeyTrack + dBVel * ampVelTrack + sfzVolume);
            //check if we have finished before we have begun
            return(voiceparams.generatorParams[0].currentState != GeneratorStateEnum.Finished && voiceparams.envelopes[2].CurrentState != EnvelopeStateEnum.None);
        }
Esempio n. 25
0
 public override void Stop(VoiceParameters voiceparams)
 {
     voiceparams.envelopes[0].Release();
     voiceparams.envelopes[1].Release();
 }
Esempio n. 26
0
 public async Task <YandexTtsResponse> MarkupToSpeechAsync(string text, VoiceParameters voice, FormatParameters format, CancellationToken cancellationToken = default) =>
 await InvokeAsync(text, true, voice, format, cancellationToken);
Esempio n. 27
0
 public override bool Start(VoiceParameters voiceparams)
 {
     return(false);
 }
Esempio n. 28
0
        public override void Process(VoiceParameters voiceparams, int startIndex, int endIndex)
        {
            //--Base pitch calculation
            double carrierPitch = SynthHelper.CentsToPitch((voiceparams.note - voiceparams.generators[0].RootKey) * voiceparams.generators[0].KeyTrack + voiceparams.generators[0].Tune + voiceparams.synth.totalPitch[voiceparams.channel])
                                  * voiceparams.generators[0].Period * voiceparams.generators[0].Frequency * cIndex / voiceparams.synth.SampleRate;
            double modulatorPitch = SynthHelper.CentsToPitch((voiceparams.note - voiceparams.generators[1].RootKey) * voiceparams.generators[1].KeyTrack + voiceparams.generators[1].Tune + voiceparams.synth.totalPitch[voiceparams.channel])
                                    * voiceparams.generators[1].Period * voiceparams.generators[1].Frequency * mIndex / voiceparams.synth.SampleRate;
            //--Base volume calculation
            float baseVolume = voiceparams.volOffset * voiceparams.synth.totalVolume[voiceparams.channel];

            //--Main Loop
            for (int x = startIndex; x < endIndex; x += Synthesizer.DefaultBlockSize * voiceparams.synth.AudioChannels)
            {
                //--Calculate pitch modifications
                double pitchMod;
                if (voiceparams.synth.modWheel[voiceparams.channel] != 0.0)
                {
                    voiceparams.lfos[0].Increment(Synthesizer.DefaultBlockSize);
                    pitchMod = SynthHelper.CentsToPitch((int)(voiceparams.lfos[0].Value * voiceparams.synth.modWheel[voiceparams.channel]));
                }
                else
                {
                    pitchMod = 1;
                }
                //--Get amplitude values for carrier and modulator
                voiceparams.envelopes[0].Increment(Synthesizer.DefaultBlockSize);
                voiceparams.envelopes[1].Increment(Synthesizer.DefaultBlockSize);
                float c_amp = baseVolume * voiceparams.envelopes[0].Value;
                float m_amp = voiceparams.envelopes[1].Value;
                //--Interpolator for modulator amplitude
                float linear_m_amp = (m_amp - voiceparams.mixing[2]) / Synthesizer.DefaultBlockSize;
                //--Process block
                for (int i = 0; i < voiceparams.blockBuffer.Length; i++)
                {
                    //calculate current modulator amplitude
                    voiceparams.mixing[2] += linear_m_amp;
                    //calculate sample
                    voiceparams.blockBuffer[i] = voiceparams.generators[0].GetValue(voiceparams.counters[0] + voiceparams.mixing[2] * voiceparams.generators[1].GetValue(voiceparams.counters[1] + voiceparams.counters[2] * feedBack));
                    //store sample for feedback calculation
                    voiceparams.counters[2] = voiceparams.blockBuffer[i];
                    //increment phase counters
                    voiceparams.counters[0] += carrierPitch * pitchMod;
                    voiceparams.counters[1] += modulatorPitch * pitchMod;
                }
                voiceparams.mixing[2] = m_amp;
                //--Mix block based on number of channels
                if (voiceparams.synth.AudioChannels == 2)
                {
                    SynthHelper.MixMonoToStereoInterpolation(x,
                                                             c_amp * voiceparams.synth.panPositions[voiceparams.channel].Left,
                                                             c_amp * voiceparams.synth.panPositions[voiceparams.channel].Right,
                                                             voiceparams);
                }
                else
                {
                    SynthHelper.MixMonoToMonoInterpolation(x, c_amp, voiceparams);
                }
                //--Bounds check
                if (sync == SyncMode.Soft)
                {
                    if (voiceparams.counters[0] >= voiceparams.generators[0].LoopEndPhase)
                    {
                        voiceparams.counters[0] = voiceparams.generators[0].LoopStartPhase + (voiceparams.counters[0] - voiceparams.generators[0].LoopEndPhase) % (voiceparams.generators[0].LoopEndPhase - voiceparams.generators[0].LoopStartPhase);
                    }
                    if (voiceparams.counters[1] >= voiceparams.generators[1].LoopEndPhase)
                    {
                        voiceparams.counters[1] = voiceparams.generators[1].LoopStartPhase + (voiceparams.counters[1] - voiceparams.generators[1].LoopEndPhase) % (voiceparams.generators[1].LoopEndPhase - voiceparams.generators[1].LoopStartPhase);
                    }
                }
                else
                {
                    if (voiceparams.counters[0] >= voiceparams.generators[0].LoopEndPhase)
                    {
                        voiceparams.counters[0] = voiceparams.generators[0].LoopStartPhase;
                        voiceparams.counters[1] = voiceparams.generators[1].LoopStartPhase;
                    }
                }
                //--Check and end early if necessary
                if (voiceparams.envelopes[0].CurrentState == EnvelopeStateEnum.None)
                {
                    voiceparams.state = VoiceStateEnum.Stopped;
                    return;
                }
            }
        }
Esempio n. 29
0
        private async void btnVoice_Click(object sender, RoutedEventArgs e)
        {
            VoiceMsg ObjectVoiceMsg = new VoiceMsg();
            var      content        = await ObjectVoiceMsg.ShowAsync();

            if (content == ContentDialogResult.Primary)
            {
                if (ObjectVoiceMsg.AuthCode == null)
                {
                    var dialog = new MessageDialog("Please Enter AuthCode!", "Alert");
                    await dialog.ShowAsync();
                }
                else if (ObjectVoiceMsg.VoiceMsgStatus == null)
                {
                    var dialog = new MessageDialog("Please Select Voice Result Options", "Alert");
                    await dialog.ShowAsync();
                }
                else
                {
                    txtResponse.Text = "Processing ...";

                    PaymentManager mgr = PaymentManager.Instance;
                    mgr.setPaymentResponseListener(this);

                    VoiceParameters voiceParameters = new VoiceParameters();

                    voiceParameters.amount   = result.Text.Trim();
                    voiceParameters.authcode = ObjectVoiceMsg.AuthCode;

#if (SHIFT4)
                    Shift4VoiceParameters gwvoiceParams = new Shift4VoiceParameters();
                    gwvoiceParams.cardtoken             = lastTokenValueID;
                    gwvoiceParams.customerReference     = Settings.customerReference;
                    gwvoiceParams.destinationPostalCode = Settings.destinationPostalCode;
                    gwvoiceParams.invoice         = lastTransactionID;
                    gwvoiceParams.requestCategory = ObjectVoiceMsg.VoiceMsgStatus;
                    gwvoiceParams.tax             = Settings.tax;
                    gwvoiceParams.tip             = Settings.tip;

                    ObservableCollection <string> ob = new ObservableCollection <string>();

                    ob.Add("salmon");
                    ob.Add("tuna");

                    gwvoiceParams.productDescriptors = ob;
#endif
#if (CREDITCALL)
                    CCVoiceParams gwvoiceParams = new CCVoiceParams();
                    gwvoiceParams.CardEaseReference = lastTransactionID;
                    gwvoiceParams.voiceResult       = "APPROVED";
#endif

                    voiceParameters.gatewayVoiceParams = gwvoiceParams;

                    await mgr.voiceTransaction(voiceParameters);

                    // should not repeat in the next transaciton.
                    Settings.tax = null;
                    Settings.tip = null;
                }
            }
        }
Esempio n. 30
0
 public override void Stop(VoiceParameters voiceparams)
 {
 }