0

I have created a simple command line program to turn text into a .WAV file.

The program takes 2 arguments

  1. The path to create the .WAV File
  2. The text to turn into a .WAV

This is the error I am getting on the line where I try to set the output to the default audio device:

Object reference not set to an instance of an object. at System.Speech.Internal.ObjectTokens.SAPICategories.DefaultDeviceOut() at System.Speech.Internal.Synthesis.VoiceSynthesis..ctor(WeakReference speechSynthesizer) at System.Speech.Synthesis.SpeechSynthesizer.get_VoiceSynthesizer() at System.Speech.Synthesis.SpeechSynthesizer.SetOutputToNull() at System.Speech.Synthesis.SpeechSynthesizer.SetOutputStream(Stream stream, SpeechAudioFormatInfo formatInfo, Boolean headerInfo, Boolean closeStreamOnExit) at System.Speech.Synthesis.SpeechSynthesizer.SetOutputToDefaultAudioDevice() at TTS.Program.Main(String[] args) "

Any help on this would be greatly appreciated.

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);
                }
            }
        }
    }
}
user2864740
  • 60,010
  • 15
  • 145
  • 220
Blindman
  • 9
  • 2
  • I should say I can run it fine in Visual Studio, but when I deploy it to my PHP server and call it from my code, I get this error. I can log on to the PHP server and call it from a command line just fine as well. – Blindman Aug 27 '15 at 04:11
  • 1
    (I don't think it's a duplicate per se, as the error seems to come from within SpeechSynthesizer code - but..) – user2864740 Aug 27 '15 at 04:11
  • Make sure to include such relevant information *in* the post! How is this being 'called' from PHP? It sounds like it is just an environmental difference in that case - eg. the environment in which is fails has no '[default] audio device'. – user2864740 Aug 27 '15 at 04:12
  • I tried removing the line: synthesizer.SetOutputToDefaultAudioDevice(); However, it just fails on the next call synthesizer.Volume = 100; with the same error – Blindman Aug 27 '15 at 04:17
  • Just simplified my initial code and still getting the error. It is only erroring out when I call it from the PHP page, but I can go on to the PHP server, open a command line and it works perfectly. Does the executable get called differently when called in PHP/IIS7? The PHP call does create a .wav file, but it is zero bites. – Blindman Aug 27 '15 at 18:46
  • Possibly related: http://stackoverflow.com/q/7021200/2864740 - voted to re-open – user2864740 Aug 27 '15 at 20:05
  • user2864740, you are awesome!!! The problem was with the security of the AppPool in IIS. When I changed it to an administrator account, it worked perfectly! Thank you so much for your help on this!!! – Blindman Aug 27 '15 at 21:15
  • Cool. Glad you got it working.. just keep in mind the security implications using a more elevated account. I'm not very good with mucking with manifests or security settings though. – user2864740 Aug 27 '15 at 22:46

0 Answers0