Wav to MP3 missing 20% of audio at the end












1















I've built a console app that reads a text file in two languages (english and russian) so i can make my own audio lessons.



Everything works fine, except that now I have modified it to convert the Wav audio stream to MP3 using Naudio, I'm missing around 20% of the recording at the end.



I've run code to track the capacity of the memory stream after each utterance, and sure enough, it is missing data at the end.



I'm suspecting it has something to do with the RIFF header created in the Wav stream.



I'll post the code, if I can work out how!



using System;
using System.Text;
using System.Speech.Synthesis;
using System.Speech.AudioFormat;
using System.IO;
using NAudio.Wave;
using NAudio.Lame;
using NAudio;
using System.Threading.Tasks;


namespace Immercia
{

class Program
{



public static void ConvertWavStreamToMp3File(ref MemoryStream ms, string savetofilename)
{
//rewind to beginning of stream
ms.Seek(0, SeekOrigin.Begin);

using (var rdr = new WaveFileReader(ms))
using (var wtr = new LameMP3FileWriter(savetofilename, rdr.WaveFormat, 128/* LAMEPreset.VBR_90*/))

{
rdr.CopyTo(wtr);

}
}


public static void Main(string args)
{
Console.Title = "Immercia";

MemoryStream ms = new MemoryStream();


//Create two instances of speech Synthesizer, set voices, and volume -rate is set in the function below
SpeechSynthesizer synthE = new SpeechSynthesizer();
SpeechSynthesizer synthR = new SpeechSynthesizer();
synthE.SelectVoice("Microsoft Anna");
synthR.SelectVoice("IVONA 2 Tatyana OEM");
//new SpeechAudioFormatInfo(22000, AudioBitsPerSample.Sixteen, AudioChannel.Mono);



synthE.Volume = 100;
synthR.Volume = 85;
synthE.Rate = -4;
synthE.SetOutputToWaveStream(ms);
synthR.SetOutputToWaveStream(ms);



// Set up the input text file to be read, and the output .wav file to be created
Console.WriteLine("Enter exact lesson name to be read (case sensitive), " +
"do not include path or file extention");
string LessonName = Console.ReadLine();

//Console.WriteLine("Enter unique Wav File name to be created (case sensitive), " +
// "do not include path or file extention ");
string WavFileName = LessonName;

//The output mp3 file of the recorded audio
string savetofilename = @"C:RussianLessons" + WavFileName + ".mp3";

Console.OutputEncoding = Encoding.UTF8;

/*Source file for text to speech. must be created with an asterix before the english,
and a 4 digit "pause time" entry before the russian in milliseconds i.e."1400"
Creation note: file mus be saved as a txt file in unicode UFT8 or UFT 16 to support cryllic.*/

string lesson = File.ReadAllLines(@"C:RussianLessons" + LessonName + ".txt");

//this fixes the problem of the MP3 not recording the first word/phrase of the lesson,but doesn't actually get recorded???? weird stuff.
synthR.Speak("Здравствуйте");

try
{


// Loop over strings.
foreach (string word in lesson)
{
//Trim off english indicator asterix and create new string "english" for speaking.
if (word.Contains("*") == true)
{
char trim = '*';
string english = word.Trim(trim);

//write english word to console
Console.WriteLine(english);

//speak english word

synthE.Speak(english);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

}
if (word.Contains("#") == true)
{

//Trim off pause time instructions to leave crylllic to be written to console
char charsToTrim = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '#' };
string TrimmedRussian = word.TrimStart(charsToTrim);

//extract pause time entry from the begining of the russian word string
string milli = word.Substring(0, 4);
string pause = string.Concat('"' + milli + "ms"");

//create SSML string to allow for "pause time" to be read automatically by the speech synthesizer
string russian;
russian = "<speak version="1.0"";
russian += " xmlns="http://www.w3.org/2001/10/synthesis "";
russian += " xml:lang="ru-RU">";
russian += TrimmedRussian;
russian += "<break time= ";
russian += pause;
russian += " />";
russian += "</speak>";

//Write russian word to console
Console.WriteLine(TrimmedRussian);

//speak russian word
synthR.Rate = -6;

synthR.SpeakSsml(russian);
//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

synthR.Rate = -4;
// repeat russian word
synthR.SpeakSsml(russian);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

}
/* if (word.Contains("end of file") == true)
{

synthR.Speak("До свидания, До свидания, До свидания");

}*/

}

//This is not being spoken???? Trying to fix the loss of 20% of the bytes from the end of the MP3.
//Having synthR speak before the foreach fixed the loss of the first 20%....

//synthR.Speak("Здравствуйте");

}

catch (FileNotFoundException)
{
// Write error.
Console.WriteLine("Lesson file not found or spelt incorrectly, " +
"please restart program and check the file name and remember it is case sensitive.");
}



//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());



ConvertWavStreamToMp3File(ref ms, savetofilename);

ms.Close();

//Stop fucking around with C# and learn Russian, NOW....
Console.WriteLine("n That is all, press any key to exit");
Console.ReadKey();


}

}


}










share|improve this question

























  • Whoops, was hoping to post the code...

    – Andrew Haas
    Nov 19 '18 at 10:19











  • I found this comment by Mark Heath answering a question about wav file headers. It seems to be what I'm looking for. Now I just need to find out how to actually do what he says. stackoverflow.com/questions/39328396/…

    – Andrew Haas
    Nov 20 '18 at 10:42













  • Hi Andrew, just a tip - if you tag your question with the appropriate language tag, it will automatically show your code with correct highlights so it's easier for everyone to read... (I.e., "c#", or whatever)

    – Ian
    Nov 22 '18 at 12:48








  • 1





    Thanks Ian! Will do from now on. :)

    – Andrew Haas
    Nov 22 '18 at 12:50











  • Looks better ;)

    – Ian
    Nov 22 '18 at 12:51
















1















I've built a console app that reads a text file in two languages (english and russian) so i can make my own audio lessons.



Everything works fine, except that now I have modified it to convert the Wav audio stream to MP3 using Naudio, I'm missing around 20% of the recording at the end.



I've run code to track the capacity of the memory stream after each utterance, and sure enough, it is missing data at the end.



I'm suspecting it has something to do with the RIFF header created in the Wav stream.



I'll post the code, if I can work out how!



using System;
using System.Text;
using System.Speech.Synthesis;
using System.Speech.AudioFormat;
using System.IO;
using NAudio.Wave;
using NAudio.Lame;
using NAudio;
using System.Threading.Tasks;


namespace Immercia
{

class Program
{



public static void ConvertWavStreamToMp3File(ref MemoryStream ms, string savetofilename)
{
//rewind to beginning of stream
ms.Seek(0, SeekOrigin.Begin);

using (var rdr = new WaveFileReader(ms))
using (var wtr = new LameMP3FileWriter(savetofilename, rdr.WaveFormat, 128/* LAMEPreset.VBR_90*/))

{
rdr.CopyTo(wtr);

}
}


public static void Main(string args)
{
Console.Title = "Immercia";

MemoryStream ms = new MemoryStream();


//Create two instances of speech Synthesizer, set voices, and volume -rate is set in the function below
SpeechSynthesizer synthE = new SpeechSynthesizer();
SpeechSynthesizer synthR = new SpeechSynthesizer();
synthE.SelectVoice("Microsoft Anna");
synthR.SelectVoice("IVONA 2 Tatyana OEM");
//new SpeechAudioFormatInfo(22000, AudioBitsPerSample.Sixteen, AudioChannel.Mono);



synthE.Volume = 100;
synthR.Volume = 85;
synthE.Rate = -4;
synthE.SetOutputToWaveStream(ms);
synthR.SetOutputToWaveStream(ms);



// Set up the input text file to be read, and the output .wav file to be created
Console.WriteLine("Enter exact lesson name to be read (case sensitive), " +
"do not include path or file extention");
string LessonName = Console.ReadLine();

//Console.WriteLine("Enter unique Wav File name to be created (case sensitive), " +
// "do not include path or file extention ");
string WavFileName = LessonName;

//The output mp3 file of the recorded audio
string savetofilename = @"C:RussianLessons" + WavFileName + ".mp3";

Console.OutputEncoding = Encoding.UTF8;

/*Source file for text to speech. must be created with an asterix before the english,
and a 4 digit "pause time" entry before the russian in milliseconds i.e."1400"
Creation note: file mus be saved as a txt file in unicode UFT8 or UFT 16 to support cryllic.*/

string lesson = File.ReadAllLines(@"C:RussianLessons" + LessonName + ".txt");

//this fixes the problem of the MP3 not recording the first word/phrase of the lesson,but doesn't actually get recorded???? weird stuff.
synthR.Speak("Здравствуйте");

try
{


// Loop over strings.
foreach (string word in lesson)
{
//Trim off english indicator asterix and create new string "english" for speaking.
if (word.Contains("*") == true)
{
char trim = '*';
string english = word.Trim(trim);

//write english word to console
Console.WriteLine(english);

//speak english word

synthE.Speak(english);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

}
if (word.Contains("#") == true)
{

//Trim off pause time instructions to leave crylllic to be written to console
char charsToTrim = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '#' };
string TrimmedRussian = word.TrimStart(charsToTrim);

//extract pause time entry from the begining of the russian word string
string milli = word.Substring(0, 4);
string pause = string.Concat('"' + milli + "ms"");

//create SSML string to allow for "pause time" to be read automatically by the speech synthesizer
string russian;
russian = "<speak version="1.0"";
russian += " xmlns="http://www.w3.org/2001/10/synthesis "";
russian += " xml:lang="ru-RU">";
russian += TrimmedRussian;
russian += "<break time= ";
russian += pause;
russian += " />";
russian += "</speak>";

//Write russian word to console
Console.WriteLine(TrimmedRussian);

//speak russian word
synthR.Rate = -6;

synthR.SpeakSsml(russian);
//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

synthR.Rate = -4;
// repeat russian word
synthR.SpeakSsml(russian);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

}
/* if (word.Contains("end of file") == true)
{

synthR.Speak("До свидания, До свидания, До свидания");

}*/

}

//This is not being spoken???? Trying to fix the loss of 20% of the bytes from the end of the MP3.
//Having synthR speak before the foreach fixed the loss of the first 20%....

//synthR.Speak("Здравствуйте");

}

catch (FileNotFoundException)
{
// Write error.
Console.WriteLine("Lesson file not found or spelt incorrectly, " +
"please restart program and check the file name and remember it is case sensitive.");
}



//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());



ConvertWavStreamToMp3File(ref ms, savetofilename);

ms.Close();

//Stop fucking around with C# and learn Russian, NOW....
Console.WriteLine("n That is all, press any key to exit");
Console.ReadKey();


}

}


}










share|improve this question

























  • Whoops, was hoping to post the code...

    – Andrew Haas
    Nov 19 '18 at 10:19











  • I found this comment by Mark Heath answering a question about wav file headers. It seems to be what I'm looking for. Now I just need to find out how to actually do what he says. stackoverflow.com/questions/39328396/…

    – Andrew Haas
    Nov 20 '18 at 10:42













  • Hi Andrew, just a tip - if you tag your question with the appropriate language tag, it will automatically show your code with correct highlights so it's easier for everyone to read... (I.e., "c#", or whatever)

    – Ian
    Nov 22 '18 at 12:48








  • 1





    Thanks Ian! Will do from now on. :)

    – Andrew Haas
    Nov 22 '18 at 12:50











  • Looks better ;)

    – Ian
    Nov 22 '18 at 12:51














1












1








1








I've built a console app that reads a text file in two languages (english and russian) so i can make my own audio lessons.



Everything works fine, except that now I have modified it to convert the Wav audio stream to MP3 using Naudio, I'm missing around 20% of the recording at the end.



I've run code to track the capacity of the memory stream after each utterance, and sure enough, it is missing data at the end.



I'm suspecting it has something to do with the RIFF header created in the Wav stream.



I'll post the code, if I can work out how!



using System;
using System.Text;
using System.Speech.Synthesis;
using System.Speech.AudioFormat;
using System.IO;
using NAudio.Wave;
using NAudio.Lame;
using NAudio;
using System.Threading.Tasks;


namespace Immercia
{

class Program
{



public static void ConvertWavStreamToMp3File(ref MemoryStream ms, string savetofilename)
{
//rewind to beginning of stream
ms.Seek(0, SeekOrigin.Begin);

using (var rdr = new WaveFileReader(ms))
using (var wtr = new LameMP3FileWriter(savetofilename, rdr.WaveFormat, 128/* LAMEPreset.VBR_90*/))

{
rdr.CopyTo(wtr);

}
}


public static void Main(string args)
{
Console.Title = "Immercia";

MemoryStream ms = new MemoryStream();


//Create two instances of speech Synthesizer, set voices, and volume -rate is set in the function below
SpeechSynthesizer synthE = new SpeechSynthesizer();
SpeechSynthesizer synthR = new SpeechSynthesizer();
synthE.SelectVoice("Microsoft Anna");
synthR.SelectVoice("IVONA 2 Tatyana OEM");
//new SpeechAudioFormatInfo(22000, AudioBitsPerSample.Sixteen, AudioChannel.Mono);



synthE.Volume = 100;
synthR.Volume = 85;
synthE.Rate = -4;
synthE.SetOutputToWaveStream(ms);
synthR.SetOutputToWaveStream(ms);



// Set up the input text file to be read, and the output .wav file to be created
Console.WriteLine("Enter exact lesson name to be read (case sensitive), " +
"do not include path or file extention");
string LessonName = Console.ReadLine();

//Console.WriteLine("Enter unique Wav File name to be created (case sensitive), " +
// "do not include path or file extention ");
string WavFileName = LessonName;

//The output mp3 file of the recorded audio
string savetofilename = @"C:RussianLessons" + WavFileName + ".mp3";

Console.OutputEncoding = Encoding.UTF8;

/*Source file for text to speech. must be created with an asterix before the english,
and a 4 digit "pause time" entry before the russian in milliseconds i.e."1400"
Creation note: file mus be saved as a txt file in unicode UFT8 or UFT 16 to support cryllic.*/

string lesson = File.ReadAllLines(@"C:RussianLessons" + LessonName + ".txt");

//this fixes the problem of the MP3 not recording the first word/phrase of the lesson,but doesn't actually get recorded???? weird stuff.
synthR.Speak("Здравствуйте");

try
{


// Loop over strings.
foreach (string word in lesson)
{
//Trim off english indicator asterix and create new string "english" for speaking.
if (word.Contains("*") == true)
{
char trim = '*';
string english = word.Trim(trim);

//write english word to console
Console.WriteLine(english);

//speak english word

synthE.Speak(english);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

}
if (word.Contains("#") == true)
{

//Trim off pause time instructions to leave crylllic to be written to console
char charsToTrim = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '#' };
string TrimmedRussian = word.TrimStart(charsToTrim);

//extract pause time entry from the begining of the russian word string
string milli = word.Substring(0, 4);
string pause = string.Concat('"' + milli + "ms"");

//create SSML string to allow for "pause time" to be read automatically by the speech synthesizer
string russian;
russian = "<speak version="1.0"";
russian += " xmlns="http://www.w3.org/2001/10/synthesis "";
russian += " xml:lang="ru-RU">";
russian += TrimmedRussian;
russian += "<break time= ";
russian += pause;
russian += " />";
russian += "</speak>";

//Write russian word to console
Console.WriteLine(TrimmedRussian);

//speak russian word
synthR.Rate = -6;

synthR.SpeakSsml(russian);
//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

synthR.Rate = -4;
// repeat russian word
synthR.SpeakSsml(russian);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

}
/* if (word.Contains("end of file") == true)
{

synthR.Speak("До свидания, До свидания, До свидания");

}*/

}

//This is not being spoken???? Trying to fix the loss of 20% of the bytes from the end of the MP3.
//Having synthR speak before the foreach fixed the loss of the first 20%....

//synthR.Speak("Здравствуйте");

}

catch (FileNotFoundException)
{
// Write error.
Console.WriteLine("Lesson file not found or spelt incorrectly, " +
"please restart program and check the file name and remember it is case sensitive.");
}



//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());



ConvertWavStreamToMp3File(ref ms, savetofilename);

ms.Close();

//Stop fucking around with C# and learn Russian, NOW....
Console.WriteLine("n That is all, press any key to exit");
Console.ReadKey();


}

}


}










share|improve this question
















I've built a console app that reads a text file in two languages (english and russian) so i can make my own audio lessons.



Everything works fine, except that now I have modified it to convert the Wav audio stream to MP3 using Naudio, I'm missing around 20% of the recording at the end.



I've run code to track the capacity of the memory stream after each utterance, and sure enough, it is missing data at the end.



I'm suspecting it has something to do with the RIFF header created in the Wav stream.



I'll post the code, if I can work out how!



using System;
using System.Text;
using System.Speech.Synthesis;
using System.Speech.AudioFormat;
using System.IO;
using NAudio.Wave;
using NAudio.Lame;
using NAudio;
using System.Threading.Tasks;


namespace Immercia
{

class Program
{



public static void ConvertWavStreamToMp3File(ref MemoryStream ms, string savetofilename)
{
//rewind to beginning of stream
ms.Seek(0, SeekOrigin.Begin);

using (var rdr = new WaveFileReader(ms))
using (var wtr = new LameMP3FileWriter(savetofilename, rdr.WaveFormat, 128/* LAMEPreset.VBR_90*/))

{
rdr.CopyTo(wtr);

}
}


public static void Main(string args)
{
Console.Title = "Immercia";

MemoryStream ms = new MemoryStream();


//Create two instances of speech Synthesizer, set voices, and volume -rate is set in the function below
SpeechSynthesizer synthE = new SpeechSynthesizer();
SpeechSynthesizer synthR = new SpeechSynthesizer();
synthE.SelectVoice("Microsoft Anna");
synthR.SelectVoice("IVONA 2 Tatyana OEM");
//new SpeechAudioFormatInfo(22000, AudioBitsPerSample.Sixteen, AudioChannel.Mono);



synthE.Volume = 100;
synthR.Volume = 85;
synthE.Rate = -4;
synthE.SetOutputToWaveStream(ms);
synthR.SetOutputToWaveStream(ms);



// Set up the input text file to be read, and the output .wav file to be created
Console.WriteLine("Enter exact lesson name to be read (case sensitive), " +
"do not include path or file extention");
string LessonName = Console.ReadLine();

//Console.WriteLine("Enter unique Wav File name to be created (case sensitive), " +
// "do not include path or file extention ");
string WavFileName = LessonName;

//The output mp3 file of the recorded audio
string savetofilename = @"C:RussianLessons" + WavFileName + ".mp3";

Console.OutputEncoding = Encoding.UTF8;

/*Source file for text to speech. must be created with an asterix before the english,
and a 4 digit "pause time" entry before the russian in milliseconds i.e."1400"
Creation note: file mus be saved as a txt file in unicode UFT8 or UFT 16 to support cryllic.*/

string lesson = File.ReadAllLines(@"C:RussianLessons" + LessonName + ".txt");

//this fixes the problem of the MP3 not recording the first word/phrase of the lesson,but doesn't actually get recorded???? weird stuff.
synthR.Speak("Здравствуйте");

try
{


// Loop over strings.
foreach (string word in lesson)
{
//Trim off english indicator asterix and create new string "english" for speaking.
if (word.Contains("*") == true)
{
char trim = '*';
string english = word.Trim(trim);

//write english word to console
Console.WriteLine(english);

//speak english word

synthE.Speak(english);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

}
if (word.Contains("#") == true)
{

//Trim off pause time instructions to leave crylllic to be written to console
char charsToTrim = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '#' };
string TrimmedRussian = word.TrimStart(charsToTrim);

//extract pause time entry from the begining of the russian word string
string milli = word.Substring(0, 4);
string pause = string.Concat('"' + milli + "ms"");

//create SSML string to allow for "pause time" to be read automatically by the speech synthesizer
string russian;
russian = "<speak version="1.0"";
russian += " xmlns="http://www.w3.org/2001/10/synthesis "";
russian += " xml:lang="ru-RU">";
russian += TrimmedRussian;
russian += "<break time= ";
russian += pause;
russian += " />";
russian += "</speak>";

//Write russian word to console
Console.WriteLine(TrimmedRussian);

//speak russian word
synthR.Rate = -6;

synthR.SpeakSsml(russian);
//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

synthR.Rate = -4;
// repeat russian word
synthR.SpeakSsml(russian);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

}
/* if (word.Contains("end of file") == true)
{

synthR.Speak("До свидания, До свидания, До свидания");

}*/

}

//This is not being spoken???? Trying to fix the loss of 20% of the bytes from the end of the MP3.
//Having synthR speak before the foreach fixed the loss of the first 20%....

//synthR.Speak("Здравствуйте");

}

catch (FileNotFoundException)
{
// Write error.
Console.WriteLine("Lesson file not found or spelt incorrectly, " +
"please restart program and check the file name and remember it is case sensitive.");
}



//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());



ConvertWavStreamToMp3File(ref ms, savetofilename);

ms.Close();

//Stop fucking around with C# and learn Russian, NOW....
Console.WriteLine("n That is all, press any key to exit");
Console.ReadKey();


}

}


}







c# mp3 wav naudio






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 12:51







Andrew Haas

















asked Nov 19 '18 at 10:18









Andrew HaasAndrew Haas

65




65













  • Whoops, was hoping to post the code...

    – Andrew Haas
    Nov 19 '18 at 10:19











  • I found this comment by Mark Heath answering a question about wav file headers. It seems to be what I'm looking for. Now I just need to find out how to actually do what he says. stackoverflow.com/questions/39328396/…

    – Andrew Haas
    Nov 20 '18 at 10:42













  • Hi Andrew, just a tip - if you tag your question with the appropriate language tag, it will automatically show your code with correct highlights so it's easier for everyone to read... (I.e., "c#", or whatever)

    – Ian
    Nov 22 '18 at 12:48








  • 1





    Thanks Ian! Will do from now on. :)

    – Andrew Haas
    Nov 22 '18 at 12:50











  • Looks better ;)

    – Ian
    Nov 22 '18 at 12:51



















  • Whoops, was hoping to post the code...

    – Andrew Haas
    Nov 19 '18 at 10:19











  • I found this comment by Mark Heath answering a question about wav file headers. It seems to be what I'm looking for. Now I just need to find out how to actually do what he says. stackoverflow.com/questions/39328396/…

    – Andrew Haas
    Nov 20 '18 at 10:42













  • Hi Andrew, just a tip - if you tag your question with the appropriate language tag, it will automatically show your code with correct highlights so it's easier for everyone to read... (I.e., "c#", or whatever)

    – Ian
    Nov 22 '18 at 12:48








  • 1





    Thanks Ian! Will do from now on. :)

    – Andrew Haas
    Nov 22 '18 at 12:50











  • Looks better ;)

    – Ian
    Nov 22 '18 at 12:51

















Whoops, was hoping to post the code...

– Andrew Haas
Nov 19 '18 at 10:19





Whoops, was hoping to post the code...

– Andrew Haas
Nov 19 '18 at 10:19













I found this comment by Mark Heath answering a question about wav file headers. It seems to be what I'm looking for. Now I just need to find out how to actually do what he says. stackoverflow.com/questions/39328396/…

– Andrew Haas
Nov 20 '18 at 10:42







I found this comment by Mark Heath answering a question about wav file headers. It seems to be what I'm looking for. Now I just need to find out how to actually do what he says. stackoverflow.com/questions/39328396/…

– Andrew Haas
Nov 20 '18 at 10:42















Hi Andrew, just a tip - if you tag your question with the appropriate language tag, it will automatically show your code with correct highlights so it's easier for everyone to read... (I.e., "c#", or whatever)

– Ian
Nov 22 '18 at 12:48







Hi Andrew, just a tip - if you tag your question with the appropriate language tag, it will automatically show your code with correct highlights so it's easier for everyone to read... (I.e., "c#", or whatever)

– Ian
Nov 22 '18 at 12:48






1




1





Thanks Ian! Will do from now on. :)

– Andrew Haas
Nov 22 '18 at 12:50





Thanks Ian! Will do from now on. :)

– Andrew Haas
Nov 22 '18 at 12:50













Looks better ;)

– Ian
Nov 22 '18 at 12:51





Looks better ;)

– Ian
Nov 22 '18 at 12:51












1 Answer
1






active

oldest

votes


















0














I ended up adding another speech event into the foreach function. it's not what i was hoping for, but it worked for some reason. I do remember reading about "if" statements failing to loop, but I still suspect it's the RIFF header in the Wav stream. That's a mystery for another day. –



if (word.Contains("end") == true)
{
string millis = "1000";
string pauses = string.Concat('"' + millis + "ms"");
//create SSML string to be read automatically by the
speech synthesizer
string endfile;
endfile = "<speak version="1.0"";
endfile += " xmlns="http://www.w3.org/2001/10/synthesis "";
endfile += " xml:lang="ru-RU">";
endfile += "до свидания";
endfile += "<break time= ";
endfile += pauses;
endfile += " />";
endfile += "</speak>";

//Write russian word to console
Console.WriteLine(endfile);

//speak russian word
synthR.Rate = -6;

synthR.SpeakSsml(endfile);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

synthR.Rate = -4;
// repeat russian word
synthR.SpeakSsml(endfile);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

}





share|improve this answer


























  • i ended up adding another speech event into the foreach function. it's not what i was hoping for, but it worked for some reason. I do remember reading about "if" statements failing to loop, but I still suspect it's the RIFF header in the Wav stream. That's a mystery for another day.

    – Andrew Haas
    Nov 22 '18 at 12:48











  • Don't just post code as an answer - add some text to give context and explanation! ;) And add the text in the answer, not in a comment which might be missed...

    – Ian
    Nov 22 '18 at 12:50













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372487%2fwav-to-mp3-missing-20-of-audio-at-the-end%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














I ended up adding another speech event into the foreach function. it's not what i was hoping for, but it worked for some reason. I do remember reading about "if" statements failing to loop, but I still suspect it's the RIFF header in the Wav stream. That's a mystery for another day. –



if (word.Contains("end") == true)
{
string millis = "1000";
string pauses = string.Concat('"' + millis + "ms"");
//create SSML string to be read automatically by the
speech synthesizer
string endfile;
endfile = "<speak version="1.0"";
endfile += " xmlns="http://www.w3.org/2001/10/synthesis "";
endfile += " xml:lang="ru-RU">";
endfile += "до свидания";
endfile += "<break time= ";
endfile += pauses;
endfile += " />";
endfile += "</speak>";

//Write russian word to console
Console.WriteLine(endfile);

//speak russian word
synthR.Rate = -6;

synthR.SpeakSsml(endfile);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

synthR.Rate = -4;
// repeat russian word
synthR.SpeakSsml(endfile);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

}





share|improve this answer


























  • i ended up adding another speech event into the foreach function. it's not what i was hoping for, but it worked for some reason. I do remember reading about "if" statements failing to loop, but I still suspect it's the RIFF header in the Wav stream. That's a mystery for another day.

    – Andrew Haas
    Nov 22 '18 at 12:48











  • Don't just post code as an answer - add some text to give context and explanation! ;) And add the text in the answer, not in a comment which might be missed...

    – Ian
    Nov 22 '18 at 12:50


















0














I ended up adding another speech event into the foreach function. it's not what i was hoping for, but it worked for some reason. I do remember reading about "if" statements failing to loop, but I still suspect it's the RIFF header in the Wav stream. That's a mystery for another day. –



if (word.Contains("end") == true)
{
string millis = "1000";
string pauses = string.Concat('"' + millis + "ms"");
//create SSML string to be read automatically by the
speech synthesizer
string endfile;
endfile = "<speak version="1.0"";
endfile += " xmlns="http://www.w3.org/2001/10/synthesis "";
endfile += " xml:lang="ru-RU">";
endfile += "до свидания";
endfile += "<break time= ";
endfile += pauses;
endfile += " />";
endfile += "</speak>";

//Write russian word to console
Console.WriteLine(endfile);

//speak russian word
synthR.Rate = -6;

synthR.SpeakSsml(endfile);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

synthR.Rate = -4;
// repeat russian word
synthR.SpeakSsml(endfile);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

}





share|improve this answer


























  • i ended up adding another speech event into the foreach function. it's not what i was hoping for, but it worked for some reason. I do remember reading about "if" statements failing to loop, but I still suspect it's the RIFF header in the Wav stream. That's a mystery for another day.

    – Andrew Haas
    Nov 22 '18 at 12:48











  • Don't just post code as an answer - add some text to give context and explanation! ;) And add the text in the answer, not in a comment which might be missed...

    – Ian
    Nov 22 '18 at 12:50
















0












0








0







I ended up adding another speech event into the foreach function. it's not what i was hoping for, but it worked for some reason. I do remember reading about "if" statements failing to loop, but I still suspect it's the RIFF header in the Wav stream. That's a mystery for another day. –



if (word.Contains("end") == true)
{
string millis = "1000";
string pauses = string.Concat('"' + millis + "ms"");
//create SSML string to be read automatically by the
speech synthesizer
string endfile;
endfile = "<speak version="1.0"";
endfile += " xmlns="http://www.w3.org/2001/10/synthesis "";
endfile += " xml:lang="ru-RU">";
endfile += "до свидания";
endfile += "<break time= ";
endfile += pauses;
endfile += " />";
endfile += "</speak>";

//Write russian word to console
Console.WriteLine(endfile);

//speak russian word
synthR.Rate = -6;

synthR.SpeakSsml(endfile);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

synthR.Rate = -4;
// repeat russian word
synthR.SpeakSsml(endfile);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

}





share|improve this answer















I ended up adding another speech event into the foreach function. it's not what i was hoping for, but it worked for some reason. I do remember reading about "if" statements failing to loop, but I still suspect it's the RIFF header in the Wav stream. That's a mystery for another day. –



if (word.Contains("end") == true)
{
string millis = "1000";
string pauses = string.Concat('"' + millis + "ms"");
//create SSML string to be read automatically by the
speech synthesizer
string endfile;
endfile = "<speak version="1.0"";
endfile += " xmlns="http://www.w3.org/2001/10/synthesis "";
endfile += " xml:lang="ru-RU">";
endfile += "до свидания";
endfile += "<break time= ";
endfile += pauses;
endfile += " />";
endfile += "</speak>";

//Write russian word to console
Console.WriteLine(endfile);

//speak russian word
synthR.Rate = -6;

synthR.SpeakSsml(endfile);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

synthR.Rate = -4;
// repeat russian word
synthR.SpeakSsml(endfile);

//Test for debug of end file loss
Console.WriteLine(
"Capacity = {0}, Length = {1}, Position = {2}n",
ms.Capacity.ToString(),
ms.Length.ToString(),
ms.Position.ToString());

}






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 22 '18 at 12:53

























answered Nov 22 '18 at 12:46









Andrew HaasAndrew Haas

65




65













  • i ended up adding another speech event into the foreach function. it's not what i was hoping for, but it worked for some reason. I do remember reading about "if" statements failing to loop, but I still suspect it's the RIFF header in the Wav stream. That's a mystery for another day.

    – Andrew Haas
    Nov 22 '18 at 12:48











  • Don't just post code as an answer - add some text to give context and explanation! ;) And add the text in the answer, not in a comment which might be missed...

    – Ian
    Nov 22 '18 at 12:50





















  • i ended up adding another speech event into the foreach function. it's not what i was hoping for, but it worked for some reason. I do remember reading about "if" statements failing to loop, but I still suspect it's the RIFF header in the Wav stream. That's a mystery for another day.

    – Andrew Haas
    Nov 22 '18 at 12:48











  • Don't just post code as an answer - add some text to give context and explanation! ;) And add the text in the answer, not in a comment which might be missed...

    – Ian
    Nov 22 '18 at 12:50



















i ended up adding another speech event into the foreach function. it's not what i was hoping for, but it worked for some reason. I do remember reading about "if" statements failing to loop, but I still suspect it's the RIFF header in the Wav stream. That's a mystery for another day.

– Andrew Haas
Nov 22 '18 at 12:48





i ended up adding another speech event into the foreach function. it's not what i was hoping for, but it worked for some reason. I do remember reading about "if" statements failing to loop, but I still suspect it's the RIFF header in the Wav stream. That's a mystery for another day.

– Andrew Haas
Nov 22 '18 at 12:48













Don't just post code as an answer - add some text to give context and explanation! ;) And add the text in the answer, not in a comment which might be missed...

– Ian
Nov 22 '18 at 12:50







Don't just post code as an answer - add some text to give context and explanation! ;) And add the text in the answer, not in a comment which might be missed...

– Ian
Nov 22 '18 at 12:50




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53372487%2fwav-to-mp3-missing-20-of-audio-at-the-end%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)