Greetings folks!
I'm working on a project where I will have to create WAV files of names using TTS.
I have the MS-SAPI 5.1 SDK installed on a Windows Server 2003 and use C# to write the TTS program. Apart from the default Microsoft Sam voice, I have voices from NeoSpeech TTS installed on the server.
The issue I'm having is, the program does not produce more than 1 working WAV file.
To be more specific, if I send 4 names to the program, the program creates 4 WAV files. However only the first name is converted correctly. The file size is greater than 1 kb and the file also plays in media player.
The other 3 files are created but are of size 1 kb and do not work in any media player.
I'm new to both C# and MS-SAPI but I believe I have done a decent job creating the code. I have spent days trying to figure this out but I'm out of energy now.
Any insight on this issue is greatly appreciated. Thanks for your time.
Here is my code:
using System;
using System.Collections.Generic;
using System.Collections;
using System.Text;
using SpeechLib;
using System.Threading;
namespace TTS_Text_To_Wav
{
class Gender
{
public static String MALE = "Male";
public static String FEMALE = "Female";
}
class Languages
{
public static String ENGLISH = "409;9";
public static String SPANISH = "40a";
}
class Vendor
{
public static String VOICEWARE = "Voiceware";
public static String MICROSOFT = "Microsoft";
}
class SampleTTS
{
static void Main(string[] args)
{
SampleTTS processor = null;
try
{
processor = new SampleTTS();
// get unprocessed items
ArrayList unProcessedItems = new ArrayList();
unProcessedItems.Add("Kate");
unProcessedItems.Add("Sam");
unProcessedItems.Add("Paul");
unProcessedItems.Add("Violeta");
if (unProcessedItems != null)
{
foreach (string record in unProcessedItems)
{
// convert text to wav
processor.ConvertStringToSpeechWav(record, "c:/temp/" + record + ".wav", Vendor.VOICEWARE, Gender.MALE, Languages.ENGLISH);
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
void ConvertStringToSpeechWav(String textToConvert, String pathToCreateWavFile, String vendor, String gender, String language)
{
SpVoice voice = null;
SpFileStream spFileStream = null;
try
{
spFileStream = new SpFileStream();
voice = new SpVoice();
spFileStream.Format.Type = SpeechAudioFormatType.SAFT8kHz16BitMono;
spFileStream.Open(pathToCreateWavFile, SpeechStreamFileMode.SSFMCreateForWrite, false);
voice.Voice = voice.GetVoices("Vendor=" + vendor + ";Gender=" + gender, "Language=" + language).Item(0);
voice.AudioOutputStream = spFileStream;
voice.Speak(textToConvert, SpeechVoiceSpeakFlags.SVSFlagsAsync | SpeechVoiceSpeakFlags.SVSFPurgeBeforeSpeak);
voice.WaitUntilDone(Timeout.Infinite);
}
catch (Exception e)
{
throw new Exception("Error occured in ConvertStringToSpeechWav()\n" + e.Message);
}
finally
{
if (spFileStream != null)
{
spFileStream.Close();
}
}
}
}
}
Edit:
I seem to notice some new behavior. The code works fine for Microsoft voices on the system. It is only with the NeoSpeech voices I seem to have this issue.
Does that mean my code is correct and something is wrong with the voices? For one, I got the voice from my clients so there is nothing I can do about it. Secondly these are production ready voices. I'm pretty sure they are well tested or we would have heard a lot about it.
I'm still inclined to believe something is up with the code I wrote.
Are there any other suggestions available? I'm in a real fix here and any help will be appreciated.