Logging

テキストを日本語ボイスに変換してくれるしょぼいWindowsソフトを作ったよ。

VS2017のC#で、テキストを日本語ボイスに変換してくれるしょぼいWindowsソフト( 滑舌が悪いけどYOUTUBERしたい人用)を作ったよ。自分はかなり滑舌悪いくてどもるので、YOUTUBER向かないのですがユーチューバーしてみたい願望があったので、Gさんの「Cloud Text-to-Speech API」で適当に作ってみた。ちなみにまだYOUTUBERするかは決めてない!

APIですが月に0?100万文字までは無料枠なので、大量に使わない限り無料枠で収まると思います。これを他の人に提供しようとするとアウトだろうけど・・。
自分だけが使用するのには何とかその範囲内かと思います。

尚、ソースコードを提供します可変してお好みで使ってください。大量のテキストをボイス変換した場合、ビジーになるかもしれません。そこら辺の処理は入れてません。またGさんからダウンロードしたJSONファイルを置いている階層に合わしてください。

参考にしたサイトは下記になります。
https://cloud.google.com/text-to-speech/docs/quickstart-client-libraries?hl=ja#client-libraries-install-csharp

フォームのオブジェクトの配置は下記になります。画像を参照ください。

ソースコードは下記になります。

using System;
using System.IO;
using System.Windows.Forms;
using Google.Cloud.TextToSpeech.V1;
namespace テキストを日本語ボイスする
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if(richTextBox1.Text.Replace("\r", "").Replace("\n", "") == "")
            {
                MessageBox.Show("文字を入力してください");
                return;
            }
            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "C:\\xxxxx\\xxxxx\\xxxxx\\xxxxx.json", EnvironmentVariableTarget.Process);
            TextToSpeechClient client = TextToSpeechClient.Create();
            SynthesisInput input = new SynthesisInput
            {
                Text = richTextBox1.Text.Replace("\r", "").Replace("\n", "")
            };
            VoiceSelectionParams voice = new VoiceSelectionParams
            {
                LanguageCode = "ja-JP",
                Name = "ja-JP-Wavenet-A",
                SsmlGender = SsmlVoiceGender.Neutral,
            };
            AudioConfig config = new AudioConfig
            {
                AudioEncoding = AudioEncoding.Mp3,
                SpeakingRate = f1(trackBar1.Value),
                Pitch = f2(trackBar2.Value),
            };
            var response = client.SynthesizeSpeech(new SynthesizeSpeechRequest
            {
                Input = input,
                Voice = voice,
                AudioConfig = config
            });
            DateTime dt = DateTime.Now;
            string dttimename = dt.ToString("yyyy-MM-dd-HH-mm-ss");
            using (Stream output = File.Create("voice-" + dttimename + ".mp3"))
            {
                response.AudioContent.WriteTo(output);
                Console.WriteLine($"Audio content written to file 'voice - " + dttimename + ".mp3'");
                MessageBox.Show("生成しました=>>voice - " + dttimename + ".mp3");
                System.Diagnostics.Process.Start(Directory.GetCurrentDirectory());
            }
        }
        private void trackBar1_ValueChanged(object sender, EventArgs e)
        {
            label3.Text = string.Format("{0:0.00}", f1(trackBar1.Value));
        }
        private void trackBar2_ValueChanged(object sender, EventArgs e)
        {
            label4.Text = string.Format("{0:0.00}", f2(trackBar2.Value));
        }
        private double f1(int a) {
            return Convert.ToDouble(a) / 100;
        }
        private double f2(int a)
        {
            return Convert.ToDouble(a) - 20;
        }
    }
}

変換したボイスはこんな感じです!







    認知度高めテイコウペンギン、YOUTUBEが苦笑wwww。前のページ

    デザイン好きなひと必見、デザイナーメンターYOUTUBER次のページ

    関連記事

    1. selective focus photographed of green mountain

      Logging

      先を読む。未来を読む。

      おはようございます。5月も最後ですね、今年は梅雨入りしても即、梅雨明…

    2. Logging

      映画、鳩の撃退法を観ましたよ。今頃…ネットフリックスで。

      おはようございます、井上陽水の氷の世界の曲は何時も聞いても凄いな。い…

    3. Logging

      Tree Of Savior "Game Review"

      Tree Of Savior "Game Review…

    4. Logging

      宇宙兄弟LIFT OFF!の感想なんかをイマゴロ。

      宇宙兄弟LIFT OFF!の感想なんかをイマゴロ書きたいと思います…

    5. Logging

      人は思い込みの中で生きていると呟いた事がある。

      人は思い込みの中で生きていると呟いた事がある。あの人はこうだと、誰も…

    6. Logging

      自然体が2人ぐらいいる。(笑:2017)

      https://www.youtube.com/watch?v=6_X…

    2020年1月
     12345
    6789101112
    13141516171819
    20212223242526
    2728293031  

    カテゴリー

    アーカイブ

    PAGE TOP