예제 #1
0
        public HttpResponseMessage GetMp3BytesForSpeechPromptCollection([FromBody] SpeechPromptCollection speechPromptCollection)
        {
            var promptBuilder = new PromptBuilder();

            foreach (var speakPause in speechPromptCollection.SpeakPauseCollection)
            {
                var speakSection = speakPause.Key;
                var pauseTime    = speakPause.Value;

                promptBuilder.AppendText(speakSection);
                AppendBreakToPrompt(promptBuilder, pauseTime);
            }

            var mp3ByteArray = SpeechAction.ConvertSpeechSynthPromptToMp3ByteArray(promptBuilder);

            var result = new HttpResponseMessage(HttpStatusCode.OK)
            {
                Content = new ByteArrayContent(mp3ByteArray)
            };

            result.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
            {
                FileName = $"Workout_Assistant_{DateTime.Now}_Workout.mp3"
            };

            //result.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/octet-stream");

            return(result);
        }
예제 #2
0
        private void SaveAsAudioButton_Click(object sender, EventArgs e)
        {
            if (ExerciseListBoxPopulated())
            {
                var speechPrompt = new PromptBuilder();

                speechPrompt.AppendText("Generated by Audio Workout Creator. Please visit Streets of Smashville Dot Com to download program.");
                AppendBreakToPrompt(speechPrompt, 0, 3);
                speechPrompt.AppendText($"Welcome to Workout Assistant. Today you will be performing {ExerciseListBox.Items.Count} exercises.");
                AppendBreakToPrompt(speechPrompt, 0, 3);

                foreach (var exercise in _workout)
                {
                    speechPrompt.AppendText($"Please get in position for exercise, {exercise.Name} for {exercise.Reps} reps at {exercise.Weight} pounds.");
                    AppendBreakToPrompt(speechPrompt, 0, 15);
                    speechPrompt.AppendText($"Time for  {exercise.Name} for {exercise.Reps} reps at {exercise.Weight} pounds. ");
                    speechPrompt.AppendText($"You will have {exercise.SetTime} seconds to complete the set.");
                    AppendBreakToPrompt(speechPrompt, 0, 5);
                    speechPrompt.AppendText($"Begin {exercise.Name}");
                    AppendBreakToPrompt(speechPrompt, 0, (exercise.SetTime / 2));
                    speechPrompt.AppendText("Half set time.");
                    AppendBreakToPrompt(speechPrompt, 0, (exercise.SetTime / 2));
                    speechPrompt.AppendText($"Good set! Time to rest. You will have {exercise.RestTime} seconds to rest.");
                    AppendBreakToPrompt(speechPrompt, 0, (exercise.RestTime / 2));
                    speechPrompt.AppendText("Half rest time.");
                    AppendBreakToPrompt(speechPrompt, 0, (exercise.RestTime / 2));
                    speechPrompt.AppendText("Rest time is over.");
                }

                speechPrompt.AppendText("Awesome workout! You are a step closer to achieving your goals! See you next time!");

                SpeechAction.ConvertSpeechSynthPromptToMp3File(speechPrompt, _savePath, VoiceSelectListBox.SelectedItem.ToString());
                MessageBox.Show($"Workout saved to {_savePath}.");
            }
            else
            {
                MessageBox.Show("There is no populated data in your workout. Saving failed.");
            }
        }