Added .mp3 export (#92)
* Update to larger bitrate * Add support for sub-voice export --------- Co-authored-by: katboi01 <59540382+katboi01@users.noreply.github.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using NAudio.Lame;
|
||||
using System.IO;
|
||||
using System;
|
||||
using UmaMusumeAudio;
|
||||
using NAudio.Wave.SampleProviders;
|
||||
using NAudio.Wave;
|
||||
|
||||
public class AudioExporter
|
||||
{
|
||||
|
||||
public static void ExportAudio(List<UmaWaveStream> a, string path, int index = -1) {
|
||||
|
||||
var l = new List<ISampleProvider>();
|
||||
if (index == -1)
|
||||
{
|
||||
foreach (var z in a)
|
||||
{
|
||||
var blah = z.ToSampleProvider();
|
||||
l.Add(blah);
|
||||
}
|
||||
} else
|
||||
{
|
||||
var blah = a[index].ToSampleProvider();
|
||||
l.Add(blah);
|
||||
}
|
||||
|
||||
|
||||
var wf = a[0].WaveFormat;
|
||||
|
||||
var mixer = new MixingSampleProvider(l);
|
||||
IWaveProvider sourceProvider = new SampleToWaveProvider16(mixer);
|
||||
|
||||
|
||||
using (var writer = new LameMP3FileWriter(path, new NAudio.Wave.WZT.WaveFormat(wf.SampleRate, wf.Channels), 320))
|
||||
{
|
||||
byte[] buffer = new byte[wf.AverageBytesPerSecond]; // Read about 1 second of audio at a time
|
||||
int bytesRead;
|
||||
|
||||
// Loop to read from the source IWaveProvider and write to the MP3 writer
|
||||
// The Read method returns 0 when there's no more data
|
||||
while ((bytesRead = sourceProvider.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
writer.Write(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11c7c93c56144a444adc503635f6aff3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user