本文整理汇总了C#中NAudio.Wave.Mp3FileReader.ReadNextFrame方法的典型用法代码示例。如果您正苦于以下问题:C# Mp3FileReader.ReadNextFrame方法的具体用法?C# Mp3FileReader.ReadNextFrame怎么用?C# Mp3FileReader.ReadNextFrame使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NAudio.Wave.Mp3FileReader
的用法示例。
在下文中一共展示了Mp3FileReader.ReadNextFrame方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CutFile
private static void CutFile(string sourceFile, int startSecond, int endSecond, string resultFile)
{
using (var reader = new Mp3FileReader(sourceFile))
{
FileStream writer = File.Create(resultFile);
Mp3Frame frame;
while ((frame = reader.ReadNextFrame()) != null)
{
var currentSecond = (int)reader.CurrentTime.TotalSeconds;
if (currentSecond >= startSecond && currentSecond <= endSecond)
{
writer.Write(frame.RawData, 0, frame.RawData.Length);
}
else
{
if (currentSecond > endSecond)
{
writer.Dispose();
break;
}
}
}
writer.Dispose();
}
}
示例2: Describe
public string Describe(string fileName)
{
var stringBuilder = new StringBuilder();
using (var reader = new Mp3FileReader(fileName))
{
Mp3WaveFormat wf = reader.Mp3WaveFormat;
stringBuilder.AppendFormat("MP3 File WaveFormat: {0} {1}Hz {2} channels {3} bits per sample\r\n",
wf.Encoding, wf.SampleRate,
wf.Channels, wf.BitsPerSample);
stringBuilder.AppendFormat("Extra Size: {0} Block Align: {1} Average Bytes Per Second: {2}\r\n",
wf.ExtraSize, wf.BlockAlign,
wf.AverageBytesPerSecond);
stringBuilder.AppendFormat("ID: {0} Flags: {1} Block Size: {2} Frames per Block: {3}\r\n",
wf.id, wf.flags, wf.blockSize, wf.framesPerBlock
);
stringBuilder.AppendFormat("Length: {0} bytes: {1} \r\n", reader.Length, reader.TotalTime);
stringBuilder.AppendFormat("ID3v1 Tag: {0}\r\n", reader.Id3v1Tag == null ? "None" : reader.Id3v1Tag.ToString());
stringBuilder.AppendFormat("ID3v2 Tag: {0}\r\n", reader.Id3v2Tag == null ? "None" : reader.Id3v2Tag.ToString());
Mp3Frame frame;
while ((frame = reader.ReadNextFrame()) != null)
{
stringBuilder.AppendFormat("{0},{1},{2}Hz,{3},{4}bps, length {5}\r\n",
frame.MpegVersion, frame.MpegLayer,
frame.SampleRate, frame.ChannelMode,
frame.BitRate, frame.FrameLength);
}
}
return stringBuilder.ToString();
}
示例3: TotalLengthMillis
public static long TotalLengthMillis(string srcFilename) {
long millis = 0;
using (var reader = new Mp3FileReader(srcFilename)) {
Mp3Frame frame;
// read this shit to the end
while ((frame = reader.ReadNextFrame()) != null) {}
millis = (long)reader.CurrentTime.TotalMilliseconds;
}
return millis;
}
示例4: AppendAllOfFile
public void AppendAllOfFile(string srcFilename)
{
using (var reader = new Mp3FileReader(srcFilename))
{
Mp3Frame frame;
while ((frame = reader.ReadNextFrame()) != null)
{
writer.Write(frame.RawData, 0, frame.RawData.Length);
}
timeTotal += reader.TotalTime;
}
}
示例5: ConcatFiles
private static void ConcatFiles(string resultFile, string sourceFile)
{
using (var reader = new Mp3FileReader(sourceFile))
{
FileStream writer = File.Open(resultFile, FileMode.Append);
Mp3Frame frame;
while ((frame = reader.ReadNextFrame()) != null)
{
writer.Write(frame.RawData, 0, frame.RawData.Length);
}
writer.Dispose();
}
}
示例6: CanDecompressAnMp3
public void CanDecompressAnMp3()
{
string testFile = @"C:\Users\Public\Music\Coldplay\X&Y\01-Square One.mp3";
using(Mp3FileReader reader = new Mp3FileReader(testFile))
{
var frameDecompressor = new DmoMp3FrameDecompressor(reader.Mp3WaveFormat);
Mp3Frame frame = null;
byte[] buffer = new byte[reader.WaveFormat.AverageBytesPerSecond];
while ((frame = reader.ReadNextFrame()) != null)
{
int decompressed = frameDecompressor.DecompressFrame(frame, buffer, 0);
Console.WriteLine("Decompressed {0} bytes to {1}", frame.FrameLength, decompressed);
}
}
}
示例7: CortarMp3
/// <summary>
/// Transforma o período selecionado em um novo MP3 utilizando o codec LAME.
/// </summary>
/// <param name="inputFile">Arquivo de Entrada.</param>
/// <param name="inicio">Início da Seleção.</param>
/// <param name="fim">Fim da Seleção.</param>
public static MemoryStream CortarMp3(string inputFile, TimeSpan? inicio, TimeSpan? fim)
{
MemoryStream writer = new MemoryStream();
using (var reader = new Mp3FileReader(inputFile))
{
Mp3Frame frame;
while ((frame = reader.ReadNextFrame()) != null)
if (reader.CurrentTime >= inicio || !inicio.HasValue)
{
if (reader.CurrentTime <= fim || !fim.HasValue)
writer.Write(frame.RawData, 0, frame.RawData.Length);
else break;
}
}
return writer;
}
示例8: Combine
public static void Combine(string[] inputFiles, Stream output)
{
foreach (string file in inputFiles)
{
Mp3FileReader reader = new Mp3FileReader(file);
if ((output.Position == 0) && (reader.Id3v2Tag != null))
{
output.Write(reader.Id3v2Tag.RawData, 0, reader.Id3v2Tag.RawData.Length);
}
Mp3Frame frame;
while ((frame = reader.ReadNextFrame()) != null)
{
output.Write(frame.RawData, 0, frame.RawData.Length);
}
}
}
示例9: TrimMp3
public static void TrimMp3(string inputPath, string outputPath, TimeSpan? begin, TimeSpan? end)
{
if (begin.HasValue && end.HasValue && begin > end)
throw new ArgumentOutOfRangeException("end", "end should be greater than begin");
using (var reader = new Mp3FileReader(inputPath))
using (var writer = System.IO.File.Create(outputPath))
{
Mp3Frame frame;
while ((frame = reader.ReadNextFrame()) != null)
if (reader.CurrentTime >= begin || !begin.HasValue)
{
if (reader.CurrentTime <= end || !end.HasValue)
writer.Write(frame.RawData, 0, frame.RawData.Length);
else break;
}
}
}
示例10: WritePieceOfSomeFile
public void WritePieceOfSomeFile(string srcFilename, double secondIn, double secondOut)
{
using (var reader = new Mp3FileReader(srcFilename))
{
if (format == null)
format = reader.WaveFormat;
Mp3Frame frame;
while ((frame = reader.ReadNextFrame()) != null)
{
if (reader.CurrentTime.TotalSeconds >= secondIn)
{
writer.Write(frame.RawData, 0, frame.RawData.Length);
}
if (reader.CurrentTime.TotalSeconds >= secondOut)
break;
}
timeTotal += TimeSpan.FromSeconds(secondOut - secondIn); //TODO: this does not account for ranges outside the length of the file
}
}
示例11: CanDecompressAnMp3
public void CanDecompressAnMp3()
{
var testFile = @"C:\Users\Public\Music\Coldplay\X&Y\01-Square One.mp3";
if (!File.Exists(testFile))
{
Assert.Ignore("{0} not found", testFile);
}
using(var reader = new Mp3FileReader(testFile))
{
var frameDecompressor = new DmoMp3FrameDecompressor(reader.Mp3WaveFormat);
Mp3Frame frame = null;
var buffer = new byte[reader.WaveFormat.AverageBytesPerSecond];
while ((frame = reader.ReadNextFrame()) != null)
{
int decompressed = frameDecompressor.DecompressFrame(frame, buffer, 0);
Debug.WriteLine(String.Format("Decompressed {0} bytes to {1}", frame.FrameLength, decompressed));
}
}
}
示例12: DescribeMp3
public static string DescribeMp3(string fileName)
{
StringBuilder stringBuilder = new StringBuilder();
using (Mp3FileReader reader = new Mp3FileReader(fileName))
{
Mp3WaveFormat wf = reader.Mp3WaveFormat;
/*
stringBuilder.AppendFormat("MP3 File WaveFormat: {0} {1}Hz {2} channels {3} bits per sample\r\n",
wf.Encoding, wf.SampleRate,
wf.Channels, wf.BitsPerSample);
stringBuilder.AppendFormat("Extra Size: {0} Block Align: {1} Average Bytes Per Second: {2}\r\n",
wf.ExtraSize, wf.BlockAlign,
wf.AverageBytesPerSecond);
stringBuilder.AppendFormat("ID: {0} Flags: {1} Block Size: {2} Frames per Block: {3}\r\n",
wf.id, wf.flags, wf.blockSize, wf.framesPerBlock
);
stringBuilder.AppendFormat("Bytes: {0} Time: {1} \r\n", reader.Length, reader.TotalTime);
stringBuilder.AppendFormat("ID3v1 Tag: {0}\r\n", reader.Id3v1Tag == null ? "None" : reader.Id3v1Tag.ToString());
stringBuilder.AppendFormat("ID3v2 Tag: {0}\r\n", reader.Id3v2Tag == null ? "None" : reader.Id3v2Tag.ToString());
*/
Mp3Frame frame;
int kbps = 0;
int frames = 0;
while ((frame = reader.ReadNextFrame()) != null)
{
/*stringBuilder.AppendFormat("{0},{1},{2}Hz,{3},{4}bps, length {5}\r\n",
frame.MpegVersion, frame.MpegLayer,
frame.SampleRate, frame.ChannelMode,
frame.BitRate, frame.FrameLength);
*/
kbps += frame.BitRate / 1000;
frames++;
}
stringBuilder.AppendFormat("Mp3 Avg Kbps: {0} ({1})", kbps / frames, Path.GetFileName(fileName));
}
return stringBuilder.ToString();
}
示例13: processStr
private void processStr(String str)
{
files.Clear();
string[] ContentLines = str.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
int len = ContentLines.Length;
int index = 0;
for (int i = 0; i < len; i++)
{
string currentLine = ContentLines[i];
string[] delim = { "." };
// delimeter
if (textBox1.Text == string.Empty)
{
if (zhRadioButton.Checked)
delim = new string[] { "。" };
else if (enRadioButton.Checked)
delim = new string[] { ",", "." };
else if (jpRadioButton.Checked)
delim = new string[] { "。" };
}
else
{
delim = textBox1.Text.Split(new char[]{' '}, StringSplitOptions.RemoveEmptyEntries);
}
//
string[] senSet = currentLine.Split(delim, StringSplitOptions.RemoveEmptyEntries);
int inLen = senSet.Length;
for (int j = 0; j < inLen; j++)
{
index++;
string destStr = senSet[j];
statusLabel.ForeColor = Color.Red;
statusLabel.Text = "处理中:"+destStr;
// length limit
if (destStr.Length > 100)
{
//Console.WriteLine(destStr);
MessageBox.Show("这句话太长了,谷歌娘根本来不及给你读嘛!");
continue;
}
//multi-thread switch
if (mThreadCheckBox.Checked)
{
para par = new para();
par.str = senSet[j];
par.index = index;
Thread newThread = new Thread(new ParameterizedThreadStart(getTTSMT));
newThread.Start(par);
newThread.Join();
}
else
{
getTTS(senSet[j], index);
statusLabel.ForeColor = Color.Red;
statusLabel.Text = "处理中:" + senSet[j];
}
}
}
// status
statusLabel.Text = "正在进行收尾工作...";
//// merge all files
string strFilePattern = prefix + "*.mp3";
string[] strFiles = Directory.GetFiles(mp3dir, strFilePattern);
//NAudio
FileStream fileStream = new FileStream(prefix+".mp3", FileMode.OpenOrCreate);
foreach (string file in strFiles)
{
Mp3FileReader reader = new Mp3FileReader(file);
if ((fileStream.Position == 0) && (reader.Id3v2Tag != null))
{
fileStream.Write(reader.Id3v2Tag.RawData, 0, reader.Id3v2Tag.RawData.Length);
}
Mp3Frame frame;
while ((frame = reader.ReadNextFrame()) != null)
{
fileStream.Write(frame.RawData, 0, frame.RawData.Length);
}
reader.Close();
}
fileStream.Close();
////
statusLabel.ForeColor = Color.Black;
statusLabel.Text = "所有句子全部完成!";
//
if (playCheckBox.Checked)
{
playMp3(prefix+".mp3");
}
if (!saveCheckBox.Checked)
{
try
{
File.Delete(prefix + ".mp3");
}
catch
{
//.........这里部分代码省略.........
示例14: PlayPieceOfAFile_t
private static void PlayPieceOfAFile_t(string srcFilename, double secondIn, double secondOut) {
IWavePlayer waveOutDevice = new WaveOut();
using (var reader = new Mp3FileReader(srcFilename)) {
waveOutDevice.Init(reader);
Mp3Frame frame;
while ((frame = reader.ReadNextFrame()) != null) {
if (reader.CurrentTime.TotalSeconds >= secondIn) {
break;
//writer.Write(frame.RawData, 0, frame.RawData.Length);
}
if (reader.CurrentTime.TotalSeconds >= secondOut)
break;
}
waveOutDevice.Play();
int millis = (int)(1000 * (secondOut - secondIn));
Thread.Sleep(millis);
}
}
示例15: trimMp3
void trimMp3(string input, string output, int startOffset, int endOffset)
{
using (Mp3FileReader reader = new Mp3FileReader(input)){
System.IO.FileStream _fs = new System.IO.FileStream(output, System.IO.FileMode.Create, System.IO.FileAccess.Write);
Mp3Frame mp3Frame;
do
{
mp3Frame = reader.ReadNextFrame();
if (mp3Frame == null) return;
if ((int)reader.CurrentTime.TotalSeconds < startOffset) continue;
if ((int)reader.CurrentTime.TotalSeconds >= endOffset) break;
_fs.Write(mp3Frame.RawData, 0, mp3Frame.RawData.Length);
} while (mp3Frame != null);
_fs.Close();
}
}