0

.WAVテキストをファイル に変換する簡単なコマンド ライン プログラムを作成しました。

プログラムは 2 つの引数を取ります

  1. .WAVファイルを作成するパス
  2. に変換するテキスト.WAV

これは、出力をデフォルトのオーディオ デバイスに設定しようとした行で発生するエラーです。

オブジェクト参照がオブジェクト インスタンスに設定されていません。System.Speech.Internal.ObjectTokens.SAPICategories.DefaultDeviceOut() で System.Speech.Internal.Synthesis.VoiceSynthesis..ctor(WeakReference speechSynthesizer) で System.Speech.Synthesis.SpeechSynthesizer.get_VoiceSynthesizer() で System.Speech.Synthesis. SpeechSynthesizer.SetOutputToNull() で System.Speech.Synthesis.SpeechSynthesizer.SetOutputStream(Stream stream, SpeechAudioFormatInfo formatInfo, Boolean headerInfo, Boolean closeStreamOnExit) で System.Speech.Synthesis.SpeechSynthesizer.SetOutputToDefaultAudioDevice() で TTS.Program.Main(String[]引数) "

これに関する任意の助けをいただければ幸いです。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Speech.Synthesis;
using System.Text;
using System.Threading.Tasks;

namespace TTS 
{
    class Program 
    {
        static SpeechSynthesizer synthesizer;

        static void Main(string[] args) 
        {
            //"..\\audio\\message.wav"

            using(System.IO.FileStream stream = System.IO.File.Create(args[0])) 
            {
                try 
                {
                    synthesizer = new SpeechSynthesizer();
                    Console.WriteLine("Creating WAV");
                    synthesizer.SetOutputToWaveStream(stream);
                    Console.WriteLine("Speaking Words");
                    synthesizer.Speak(args[1]);
                    Console.WriteLine("Disposing");
                    synthesizer.Dispose();
                    Console.WriteLine("Finished");
                } catch (Exception ex) 
                {
                    Console.WriteLine(ex.Message);
                    Console.WriteLine(ex.StackTrace);
                }
            }
        }
    }
}
4

0 に答える 0