HOME
  Security
   Software
    Hardware
  
FPGA
  CPU
   Android
    Raspberry Pi
  
nLite
  Xcode
   etc.
    ALL
  
LINK
BACK
 

2018/02/01

Windows 10対応の日本語対応の音声合成エンジン TTSアプリを C# .NETで自作する Windows 10対応の日本語対応の音声合成エンジン TTSアプリを C# .NETで自作する

(Visual Studio 2013の C# .NETで入力した文字列を喋る音声合成 TTSアプリを作成する 世界各国語に対応)

Tags: [Windows], [無人インストール]




● 過去に作成した TTS音声合成エンジンアプリが Windows 10で動かないので新規に作った

 Visual Studio 2013の C#で System.Speech.Synthesisの SpeechSynthesizerクラスを使います。
using System.Speech.Synthesis;

var synthesizer = new System.Speech.Synthesis.SpeechSynthesizer();
var voices = synthesizer.GetInstalledVoices();
synthesizer.SelectVoice(voices[voiceIndex].VoiceInfo.Name);
synth.SetOutputToDefaultAudioDevice();
synthesizer.Speak(speechStr);
synthesizer.Dispose();

 .NET Framework クラス ライブラリ > System.Speech 名前空間 > System.Speech.Synthesis
SpeechSynthesizer クラス
 インストール済みの音声合成エンジン機能へのアクセスを提供します。

 名前空間: System.Speech.Synthesis
 .NET Framework 3.0 以降で使用可能


● 過去に作成した TTS音声合成エンジンアプリ

 過去に Visual C++で作成しました。
 Windows 10では正常に動きません。(TTSエンジンを認識しない、TTS音声を選択しても日本語でしか喋らない等)

2010/06/14
音声合成エンジン(SAPI 5、TTS)を使用して入力した文字列を喋ります
音声合成エンジン(SAPI 5、TTS)を使用して入力した文字列を喋ります

  SpeechApp Microsoft Speech API 5(SAPI 5)の Text-to-Speech(TTS)のアプリ

2012/04/03
音声合成エンジン(MSSP 11、TTS)を使用して入力した文字列を喋ります
音声合成エンジン(MSSP 11、TTS)を使用して入力した文字列を喋ります

  SpeechApp11 Microsoft Speech Platform 11用の Text-to-Speech(TTS)のアプリ


● Visual Studio 2013の練習で作成した TTS音声合成エンジンアプリ

 Visual Studio 2013の練習で作成した TTS音声合成エンジンアプリ。


2018/04/15
Windows 10の音声合成エンジンを使用して入力した文字列を喋る & Waveファイル書き出し
Windows 10の音声合成エンジンを使用して入力した文字列を喋る & Waveファイル書き出し

  SpeechApp Windows 10用 Speech 音声合成 Text-to-Speech TTSのアプリ

SpeechTest.cs
 // SPEECH_ASYNCを有効にすると「非同期再生」となる
 //#define SPEECH_ASYNC

using System;
using System.Speech.Synthesis;
using System.Threading;

 // アセンブリに追加 System.Speech

namespace SpeechTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // Initialize a new instance of the SpeechSynthesizer.
            var synthesizer = new System.Speech.Synthesis.SpeechSynthesizer();

            // Returns the collection of speech synthesis TTS voices.
            var voices = synthesizer.GetInstalledVoices();

            // Display TTS voice list.
            if (args.Length == 0)
            {
                int index = 0;
                Console.WriteLine("SpeechSynthesizer.GetInstalledVoices()");
                foreach (InstalledVoice voice in voices)
                {
                    Console.WriteLine("{3}: {0,-26} {1,-26} {2, -6}", voice.VoiceInfo.Id, voice.VoiceInfo.Name, voice.VoiceInfo.Gender, index);
                    ++index;
                }
                return;
            }

            // Check args
            if (args.Length != 2)
            {
                Console.WriteLine("Error: args");
                return;
            }

            // Get Voice Index
            int voiceIndex = 0;
            try
            {
                voiceIndex = Int32.Parse(args[0]);
            }
            catch (FormatException e)
            {
                Console.WriteLine(e.Message);
                return;
            }

            // Check Voice Index
            if (voiceIndex < 0 || voiceIndex >= voices.Count)
            {
                Console.WriteLine("Error: voiceIndex");
            }

            // Speech string.
            string speechStr = args[1];

            // Selects a specific TTS voice by name.
            synthesizer.SelectVoice(voices[voiceIndex].VoiceInfo.Name);

            // Set the volume of the SpeechSynthesizer's ouput (0 ~ 100).
            synthesizer.Volume = 100;

            // Set a value for the speaking rate (-10 ~ 10).
            synthesizer.Rate = 0;

            // Configure the audio output.
            synthesizer.SetOutputToDefaultAudioDevice();

#if SPEECH_ASYNC
            ManualResetEvent speechDoneEvent = new ManualResetEvent(false);

            // Speech asynchronously.
            synthesizer.SpeakAsync(speechStr);
            synthesizer.SpeakCompleted += (s, arg) =>
            {
                // Sets the state of the event to signaled.
                speechDoneEvent.Set();
            };

            // Blocks the current thread until receives a signal.
            speechDoneEvent.WaitOne();
#else
            // Speech output synchronously.
            synthesizer.Speak(speechStr);
#endif

            // Disposes the SpeechSynthesizer object
            synthesizer.Dispose();
        }
    }
}


●エラー 1 型または名前空間名 'Speech' は名前空間 'System' に存在しません。アセンブリ参照が不足しています。

 「参照設定」で「参照の追加(R)...」で Speechで検索(絞込み)
System.Speech
 を追加する。

 .NET Framework: 3.0以降で使用可能


● Visual Studio 2013で音声認識

音声認識は SpeechRecognitionEngine.InstalledRecognizers メソッド ()のサンプルでそのまま使えます。

 認識精度はとても悪いです。(認識精度を上げるには特定の単語を認識辞書に覚えさせる必要が有ります)

SpeechRecognitionEngine.InstalledRecognizers メソッド ()


2018/04/18
Windows 10対応 Microsoft Speech使用の音声認識アプリ
Windows 10対応 Microsoft Speech使用の音声認識アプリ

  SpeechRecognizeApp 音声認識エンジンを使用してマイク入力の音声を認識します

 TwoLetterISOLanguageName.Equals("ja")で日本語を認識できる様にしています。
using System;
using System.Speech.Recognition;

namespace SpeechRecognitionApp
{
  class Program
  {
    static void Main(string[] args)
    {

      // Select a speech recognizer that supports English.
      RecognizerInfo info = null;
      foreach (RecognizerInfo ri in SpeechRecognitionEngine.InstalledRecognizers())
      {
        if (ri.Culture.TwoLetterISOLanguageName.Equals("ja"))
        {
          info = ri;
          break;
        }
      }
      if (info == null) return;

      // Create the selected recognizer.
      using (SpeechRecognitionEngine recognizer =
        new SpeechRecognitionEngine(info))
      {

        // Create and load a dictation grammar.
        recognizer.LoadGrammar(new DictationGrammar());

        // Add a handler for the speech recognized event.
        recognizer.SpeechRecognized +=
          new EventHandler<SpeechRecognizedEventArgs>(recognizer_SpeechRecognized);

        // Configure input to the speech recognizer.
        recognizer.SetInputToDefaultAudioDevice();

        // Start asynchronous, continuous speech recognition.
        recognizer.RecognizeAsync(RecognizeMode.Multiple);

        // Keep the console window open.
        while (true)
        {
          Console.ReadLine();
        }
      }
    }

    // Handle the SpeechRecognized event.
    static void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
    {
      Console.WriteLine("Recognized text: " + e.Result.Text);
    }
  }
}




Tags: [Windows], [無人インストール]

●関連するコンテンツ(この記事を読んだ人は、次の記事も読んでいます)

【2023年対応】 Microsoft Visual C++ ランタイムライブラリ 再頒布可能パッケージのまとめ 2005~2022まで
【2023年対応】 Microsoft Visual C++ ランタイムライブラリ 再頒布可能パッケージのまとめ 2005~2022まで

  Microsoft Visual C++ 2005、2008、2010、2012、2013、2015、2017、2019、2022の各バージョンの最新版 MSVC Runtime librariesのまとめ

Visual Studioの C#で開発した .Netアプリの難読化をする方法
Visual Studioの C#で開発した .Netアプリの難読化をする方法

  C#で開発した .Netアプリの難読化は必須事項です、素の状態では簡単に内部を解析されます

Visual Studioの C#で開発した .Netアプリを逆コンパイルして、中身の実装を覗き見る方法
Visual Studioの C#で開発した .Netアプリを逆コンパイルして、中身の実装を覗き見る方法

  C#で開発した .Netアプリは比較的簡単に元のソースコードに戻せます

Visual Studio 2019 Professional v16.4を無人インストールする方法、完全自動でインストール
Visual Studio 2019 Professional v16.4を無人インストールする方法、完全自動でインストール

  VS2019 v16.4を完全オフラインインストール&コンポーネント選択の事前設定で自動インストールする

Visual Studio 2017 Professional 15.9を無人インストールする方法、完全自動でインストール
Visual Studio 2017 Professional 15.9を無人インストールする方法、完全自動でインストール

  VS2017を完全オフラインインストール&コンポーネント選択の事前設定で自動インストールする

Visual Studio 2015 Professionalを無人インストールする方法、完全自動でインストール
Visual Studio 2015 Professionalを無人インストールする方法、完全自動でインストール

  VS2015を Update 3適用済みとコンポーネント選択の事前設定でインストール時の手間を省く

Visual Studio 2013 Professionalを無人インストールする方法、完全自動でインストール
Visual Studio 2013 Professionalを無人インストールする方法、完全自動でインストール

  VS2013を Update 5適用済みとコンポーネント選択の事前設定でインストール時の手間を省く

Visual Studio 2005 Professionalに Service Pack 1を統合して無人インストールする方法
Visual Studio 2005 Professionalに Service Pack 1を統合して無人インストールする方法

  VS2005に SP1を統合 & 完全自動でインストール、SP1の適用とコンポーネントの事前設定でインストールの手間を省く

Visual Studio 98を Windows 10 1903にインストールする方法
Visual Studio 98を Windows 10 1903にインストールする方法

  VS98 Visual Studio 98を Windows 10 19H1にインストールする方法

Visual Studio Communityのまとめ Professional と同等機能が無償
Visual Studio Communityのまとめ Professional と同等機能が無償

  Visual Studio Communityの 2013 Update 5、2015 Update 3、2017 version 15.6のまとめ

C# .NETで ZIPファイル解凍ツール UnZipをソースリスト 1行で自作する方法、Windows .NET専用
C# .NETで ZIPファイル解凍ツール UnZipをソースリスト 1行で自作する方法、Windows .NET専用

  Visual Studio 2013の C# .NET 4.5で ZipFile.ExtractToDirectoryを使い、UnZip解凍ツールを作成

Visual Studio 2013に Windows 10 SDK + UwpDesktopで UWPの機能を素の Windowsアプリから使用
Visual Studio 2013に Windows 10 SDK + UwpDesktopで UWPの機能を素の Windowsアプリから使用

  VS2013に Win 10 SDKをインストールして Uwp Desktopで UWPの機能を従来の Windowsアプリで動かす

Visual Studio 2013の C# .NETで 日本語対応の OCR文字認識アプリを自作する方法
Visual Studio 2013の C# .NETで 日本語対応の OCR文字認識アプリを自作する方法

  オフライン環境で動作可能な 世界各国語対応の OCR文字認識アプリを C# .NETで作成、MS製 OCRライブラリを使用

Visual Studio 2013の C#で日本語対応の手書き文字認識アプリを自作する方法
Visual Studio 2013の C#で日本語対応の手書き文字認識アプリを自作する方法

  オフライン環境で動作する世界各国語対応の手書き文字認識アプリを作成、MS製 手書き認識ライブラリを使用

Open XML SDKを使用して Officeのファイルを C#で自在に操る方法
Open XML SDKを使用して Officeのファイルを C#で自在に操る方法

  Microsoft Officeのファイルをプログラムで生成したり直接中身の読み取りができます

Visual Studioの各バージョンと開発できる .NET Frameworkの各バージョンのまとめ
Visual Studioの各バージョンと開発できる .NET Frameworkの各バージョンのまとめ

  .Microsoft.NET Framework Developer Packの各バージョンのダウンロードまとめ。言語パック等

Windows 10対応 Microsoft Speech使用の音声認識アプリ
Windows 10対応 Microsoft Speech使用の音声認識アプリ

  SpeechRecognizeApp 音声認識エンジンを使用してマイク入力の音声を認識します

Windows 10の音声合成エンジンを使用して入力した文字列を喋る & Waveファイル書き出し
Windows 10の音声合成エンジンを使用して入力した文字列を喋る & Waveファイル書き出し

  SpeechApp Windows 10用 Speech 音声合成 Text-to-Speech TTSのアプリ

Visual Studioの C#や MFC C++用のサンプルアプリのリンク集
Visual Studioの C#や MFC C++用のサンプルアプリのリンク集

  Visual Studioの C#や MFC C++でアプリを作る時の参考資料として

Windowsの Input Method Manager IMEや TSF Text Services Frameworkの公式情報源のまとめ
Windowsの Input Method Manager IMEや TSF Text Services Frameworkの公式情報源のまとめ

  Windowsで IME Input Method Manager関連のアプリを作成する時の情報 ImeTrayもこの辺を必死に読んだ

Microsoft Office 2016を無人インストール(自動インストール)する方法
Microsoft Office 2016を無人インストール(自動インストール)する方法

  インストールするコンポーネントを事前に設定する事で同一環境の構築が楽にできます MSオフィス 2016

Windows 10を全自動で最後まで手間要らずでインストールする方法
Windows 10を全自動で最後まで手間要らずでインストールする方法

  autounattend.xmlの応答ファイルを使用して Windows 10を無人インストールする。大量展開時に便利

Adobe Acrobat Reader関係のまとめ 2018年版、自動インストール、無人インストール方法
Adobe Acrobat Reader関係のまとめ 2018年版、自動インストール、無人インストール方法

  アップデート手順など、Adobe Reader XI、X、Acrobat Reader 9、Acrobat Reader 8




[HOME] | [BACK]
リンクフリー(連絡不要、ただしトップページ以外は Web構成の変更で移動する場合があります)
Copyright (c) 2018 FREE WING,Y.Sakamoto
Powered by 猫屋敷工房 & HTML Generator

http://www.neko.ne.jp/~freewing/software/visual_c_sharp_speach_tts_windows_10/