本文整理汇总了C#中NAudio.Wave.WaveFileReader.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# WaveFileReader.CopyTo方法的具体用法?C# WaveFileReader.CopyTo怎么用?C# WaveFileReader.CopyTo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NAudio.Wave.WaveFileReader
的用法示例。
在下文中一共展示了WaveFileReader.CopyTo方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertWavToMp3
public static void ConvertWavToMp3(string WavFile, string outPutFile)
{
CheckAddBinPath();
WaveFileReader rdr = new WaveFileReader(WavFile);
using (var wtr = new LameMP3FileWriter(outPutFile, rdr.WaveFormat, 128))
{
rdr.CopyTo(wtr);
rdr.Dispose();
wtr.Dispose();
return;
}
}
示例2: WavToMP3
/// <summary>
/// Convert WAV to MP3 using libmp3lame library
/// </summary>
/// <param name="waveFileName">WAV filename</param>
/// <param name="mp3FileName">MP3 filename</param>
/// <param name="bitRate">Bit rate, default 128</param>
/// <param name="artist">Optional artist name</param>
/// <param name="album">Optional album name</param>
/// <param name="setID3Tags">Set ID3 tags</param>
public static bool WavToMP3(string waveFileName, string mp3FileName, int bitRate = 128, string artist = null, string album = null, bool setID3Tags = false, string genre = "148")
{
bool result = true;
try
{
ID3TagData tags = new ID3TagData();
if (setID3Tags)
{
if (!String.IsNullOrEmpty(artist))
{
tags.Artist = artist;
tags.Album = album;
tags.Genre = genre;
}
}
using (var reader = new WaveFileReader(waveFileName))
using (var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate, tags))
reader.CopyTo(writer);
}
catch (Exception)
{
result = false;
}
return result;
}
示例3: ConvertWavStreamToMp3File
public static void ConvertWavStreamToMp3File(ref MemoryStream ms, string savetofilename)
{
//rewind to beginning of stream
ms.Seek(0, SeekOrigin.Begin);
using (var retMs = new MemoryStream())
using (var rdr = new WaveFileReader(ms))
using (var wtr = new LameMP3FileWriter(savetofilename, rdr.WaveFormat, LAMEPreset.VBR_90))
{
rdr.CopyTo(wtr);
}
}
示例4: ConvertWavStreamToMp3File
public static void ConvertWavStreamToMp3File(Configuration cfg, ref MemoryStream ms, string savetofilename)
{
//rewind to beginning of stream
ms.Seek(0, SeekOrigin.Begin);
using (var retMs = new MemoryStream())
{
using (var rdr = new WaveFileReader(ms))
{
using (var wtr = new LameMP3FileWriter(savetofilename, rdr.WaveFormat, cfg.MP3BitRate))
{
rdr.CopyTo(wtr);
wtr.Close();
}
rdr.Close();
Console.WriteLine(savetofilename + " ok.");
}
}
}
示例5: WaveToMP3
// Convert WAV to MP3 using libmp3lame library
public static void WaveToMP3(string waveFileName, string mp3FileName, int bitRate = 128)
{
using (var reader = new WaveFileReader(waveFileName))
using (var writer = new LameMP3FileWriter(mp3FileName, reader.WaveFormat, bitRate))
reader.CopyTo(writer);
}
示例6: Recognize
public void Recognize(string path) {
Log("Recognize: " + Path.GetFullPath(path));
if (!File.Exists(path)) { return; }
using (var reader = new WaveFileReader(path)) {
var tmp = buffer.Position;
reader.CopyTo(buffer);
buffer.Position = tmp;
}
}
示例7: ConvertWavStreamToMp3File
private void ConvertWavStreamToMp3File(ref MemoryStream ms, string savetofilename)
{
ms.Seek(0, SeekOrigin.Begin);
using (var rdr = new WaveFileReader(ms))
using (var wtr = new LameMP3FileWriter(savetofilename, rdr.WaveFormat, LAMEPreset.VBR_90))
{
rdr.CopyTo(wtr);
}
}
示例8: WriteMP3
// Writes wave memorystream out to a file.
private void WriteMP3(byte[] wave, string file)
{
string outputFile = file;
if (File.Exists(outputFile))
{
outputFile = this.GetAlternatePath(outputFile);
}
using (MemoryStream waveMemoryStream = new MemoryStream(wave))
{
using (WaveFileReader reader = new WaveFileReader(waveMemoryStream))
{
using (LameMP3FileWriter writer = new LameMP3FileWriter(outputFile, reader.WaveFormat, LAMEPreset.V4))
{
reader.CopyTo(writer);
}
}
}
}
示例9: ConvertWavToMp3
//this method takes an actual wav file and converts it
public static byte[] ConvertWavToMp3(string wavFile, bool deleteWavAfter)
{
byte[] mp3bytes = null;
try
{
using (var retMs = new MemoryStream())
using (var rdr = new WaveFileReader(wavFile))
using (var wtr = new LameMP3FileWriter(retMs, rdr.WaveFormat, bitRate))
{
rdr.CopyTo(wtr);
mp3bytes = retMs.ToArray();
}
if(deleteWavAfter)
{
File.Delete(wavFile);
}
}
catch (Exception e)
{
Debug.WriteLine(e);
}
return mp3bytes;
}
示例10: DownloadAndPlayItem
public override void DownloadAndPlayItem(PhraseItem item, string folder)
{
String SSMLText = String.Format(@"<?xml version=""1.0""?>
<speak xmlns=""http://www.w3.org/2001/10/synthesis"" version=""1.0"" xml:lang=""{1}"">
<p>
<s>{0}</s>
</p>
</speak>
", item.Phrase.Replace("&", "&"), SelectedVoice.Language);
try
{
new Task(() =>
{
using (MemoryStream ms = new MemoryStream())
{
ms.Seek(0, SeekOrigin.Begin);
using (var synth = new SpeechSynthesizer())
{
synth.SelectVoice(SelectedVoice.Name);
synth.Volume = Int32.Parse(SelectedDiscreteVolume);
synth.Rate = Int32.Parse(SelectedDiscreteSpeed);
synth.SetOutputToWaveStream(ms);//.SetOutputToWaveFile(String.Format("{0}\\wav22050\\{1}\\{2}.wav", folder, item.Folder, item.FileName));
synth.SpeakSsml(SSMLText);
}
ms.Seek(0, SeekOrigin.Begin);
using (WaveFileReader wav = new WaveFileReader(ms))// String.Format("{0}\\wav22050\\{1}\\{2}.wav", folder, item.Folder, item.FileName)))
{
using (FileStream fs = new FileStream(String.Format("{0}\\mp3\\{1}\\{2}.mp3", folder, item.Folder, item.FileName), FileMode.Create))
{
using (var writer = new LameMP3FileWriter(fs, wav.WaveFormat, 128))
{
wav.CopyTo(writer);
}
}
}
ms.Seek(0, SeekOrigin.Begin);
using (WaveFileReader wav = new WaveFileReader(ms))// String.Format("{0}\\wav22050\\{1}\\{2}.wav", folder, item.Folder, item.FileName)))
{
ConvertToWav(item, folder, true, new String[] { Name, SelectedVoice.Name, SelectedDiscreteSpeed, SelectedDiscreteVolume });
}
}
}).Start();
}
catch (Exception Ex)
{
Logger.Log(Ex.ToString());
}
}
示例11: GenerateMp3File
private static void GenerateMp3File(string filename = "output")
{
using (var reader = new WaveFileReader(GenerateMemoryStream()))
using (var writer = new LameMP3FileWriter(filename + ".mp3", reader.WaveFormat, LAMEPreset.ABR_32))
reader.CopyTo(writer);
}
示例12: ParseText
//.........这里部分代码省略.........
string[] lines = Regex.Split(inputText, "\n");
List<string> sentences = new List<string>();
List<string> symbols = new List<string>();
List<bool> quotes = new List<bool>();
foreach (string line in lines)
{
if (line.Length == 1 && line.GetHashCode() == -842352733)
continue;
else if (line.Length == 0)
continue;
DeleteOperation operation = DeleteOperation.None;
foreach (KeyValuePair<string, DeleteOperation> kvp in deleteDictionary)
{
if (line.Contains(kvp.Key))
{
operation = kvp.Value;
break;
}
}
if (operation == DeleteOperation.DeleteAllAfter)
break;
else if (operation == DeleteOperation.DeleteLine)
continue;
string[] quoteSplit = Regex.Split(line, "\"");
for (int q = 0; q < quoteSplit.Length; q++)
{
bool quoted = q % 2 == 1 ? true : false;
string[] parts = Regex.Split(quoteSplit[q], "([,…。:?!])");
string sentence = "";
string symbol = "";
//Console.WriteLine("======" + parts.Length);
for (int i = 0; i < parts.Length; i++)
{
if (parts[i].Length == 0)
continue;
sentence = parts[i];
while (i + 1 < parts.Length)
{
//Console.WriteLine("Symbol " + parts[i + 1] + " " + parts[i + 1].GetHashCode());
if (parts[i + 1].GetHashCode() == 757602046)
{
i++;
continue;
}
if (",…。:?!".Contains(parts[i + 1]))
{
symbol += parts[i + 1];
i++;
continue;
}
break;
}
if (symbol.Length == 0)
symbol = "。";
//BuildPrompt(sentence, symbol, quoted);
sentences.Add(sentence);
symbols.Add(symbol);
quotes.Add(quoted);
sentence = "";
symbol = "";
}
}
}
for (int i = 0; i < sentences.Count; i++)
{
BuildPrompt(sentences[i], symbols[i], quotes[i]);
int percent = (int)(100.0f * (float)(i + 1) / (float)sentences.Count);
//Console.Write("\r " + fileName + " Progress: {0}% ", percent);
Console.WriteLine(percent);
}
if (outputFileLocation != null)
{
ms.Seek(0, SeekOrigin.Begin);
//Convert from wav to mp3 to save space
using (var rdr = new WaveFileReader(ms))
using (var wtr = new LameMP3FileWriter(outputFileLocation, rdr.WaveFormat, LAMEPreset.VBR_90))
{
rdr.CopyTo(wtr);
}
}
}
示例13: ReadFileAndConvertToMp3
private byte[] ReadFileAndConvertToMp3()
{
using (var reader = new WaveFileReader(this._fileName))
using (var result = new MemoryStream())
using (var mp3Writer = new LameMP3FileWriter(result, reader.WaveFormat, (int)this._settings.BitRate))
{
if (reader.TotalTime.TotalSeconds <= this._settings.SecondsToSkipSongsUnder)
return new byte[0];
reader.CopyTo(mp3Writer);
return result.ToArray();
}
}