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:
|
||||
@@ -1,4 +1,10 @@
|
||||
#if !UNITY_ANDROID || UNITY_EDITOR
|
||||
using SFB;
|
||||
#endif
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using TMPro;
|
||||
using UmaMusumeAudio;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -63,6 +69,31 @@ public class UISettingsSound : MonoBehaviour
|
||||
LyricsText.text = "";
|
||||
}
|
||||
|
||||
public void ExportAudio()
|
||||
{
|
||||
#if !UNITY_ANDROID || UNITY_EDITOR
|
||||
var LiveSources = Builder.CurrentLiveSoundAWB;
|
||||
if (LiveSources.Count > 0)
|
||||
{
|
||||
var lists = new List<UmaWaveStream>();
|
||||
foreach (var source in LiveSources) {
|
||||
var z = Builder.LoadAudioStreams(source);
|
||||
foreach (var item in z)
|
||||
{
|
||||
lists.Add(item);
|
||||
}
|
||||
}
|
||||
|
||||
var path = StandaloneFileBrowser.SaveFilePanel("Save Music MP3 File", Config.Instance.MainPath, $"{TitleText.text}", "mp3");
|
||||
if (!string.IsNullOrEmpty(path))
|
||||
{
|
||||
AudioExporter.ExportAudio(lists, path, Builder.CurrentLiveSoundAWBIndex);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public void AudioProgressChange(float val)
|
||||
{
|
||||
if (Builder.CurrentAudioSources.Count > 0)
|
||||
|
||||
@@ -33,6 +33,10 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
public List<AudioSource> CurrentAudioSources = new List<AudioSource>();
|
||||
public List<UmaLyricsData> CurrentLyrics = new List<UmaLyricsData>();
|
||||
|
||||
// Used for keeping track for exports
|
||||
public List<UmaDatabaseEntry> CurrentLiveSoundAWB = new List<UmaDatabaseEntry>();
|
||||
public int CurrentLiveSoundAWBIndex = -1;
|
||||
|
||||
public AnimatorOverrideController OverrideController;
|
||||
public AnimatorOverrideController FaceOverrideController;
|
||||
public AnimatorOverrideController CameraOverrideController;
|
||||
@@ -754,10 +758,13 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
//Use decrypt function
|
||||
public void LoadLiveSound(int songid, UmaDatabaseEntry SongAwb, bool needLyrics = true)
|
||||
{
|
||||
CurrentLiveSoundAWBIndex = -1; // mix awb together
|
||||
CurrentLiveSoundAWB.Clear();
|
||||
//load character voice
|
||||
if (SongAwb != null)
|
||||
{
|
||||
PlaySound(SongAwb);
|
||||
CurrentLiveSoundAWB.Add(SongAwb);
|
||||
}
|
||||
|
||||
//load BG
|
||||
@@ -769,6 +776,7 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
if (BGclip.Count > 0)
|
||||
{
|
||||
AddAudioSource(BGclip[0]);
|
||||
CurrentLiveSoundAWB.Add(BGawb);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -812,6 +820,13 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
|
||||
}
|
||||
|
||||
public void SetLastAudio(UmaDatabaseEntry AudioAwb, int index)
|
||||
{
|
||||
CurrentLiveSoundAWB.Clear();
|
||||
CurrentLiveSoundAWB.Add(AudioAwb);
|
||||
CurrentLiveSoundAWBIndex = index;
|
||||
}
|
||||
|
||||
private void AddAudioSource(AudioClip clip, float volume = 1, bool loop = false)
|
||||
{
|
||||
AudioSource source;
|
||||
@@ -830,6 +845,27 @@ public class UmaViewerBuilder : MonoBehaviour
|
||||
source.Play();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public List<UmaWaveStream> LoadAudioStreams(UmaDatabaseEntry awb)
|
||||
{
|
||||
var streams = new List<UmaWaveStream>();
|
||||
string awbPath = awb.FilePath;
|
||||
if (!File.Exists(awbPath)) return streams;
|
||||
|
||||
FileStream awbFile = File.OpenRead(awbPath);
|
||||
AwbReader awbReader = new AwbReader(awbFile);
|
||||
|
||||
foreach (Wave wave in awbReader.Waves)
|
||||
{
|
||||
var stream = new UmaWaveStream(awbReader, wave.WaveId);
|
||||
streams.Add(stream);
|
||||
}
|
||||
|
||||
|
||||
return streams;
|
||||
}
|
||||
|
||||
public static List<AudioClip> LoadAudio(UmaDatabaseEntry awb)
|
||||
{
|
||||
List<AudioClip> clips = new List<AudioClip>();
|
||||
|
||||
@@ -798,6 +798,7 @@ public class UmaViewerUI : MonoBehaviour
|
||||
container.Button.onClick.AddListener(() =>
|
||||
{
|
||||
HighlightChildImage(NormalSubSoundList.content, container);
|
||||
Builder.SetLastAudio(awb, subSounds.IndexOf(sound));
|
||||
Builder.PlaySound(awb, subSounds.IndexOf(sound));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
"GUID:d60799ab2a985554ea1a39cd38695018",
|
||||
"GUID:fd1d627189c561043911a07470238b9c",
|
||||
"GUID:145e2572884581c48a08acf566c1a1d6",
|
||||
"GUID:86ee6720b4f4f604caf8a6add1fd3b06"
|
||||
"GUID:86ee6720b4f4f604caf8a6add1fd3b06",
|
||||
"GUID:a22e31da5d6009e499a237fb7d439ebc"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
|
||||
Reference in New Issue
Block a user