make me a unity runtime script that inferences perfectly with this class.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
[Serializable]
public class ACEStepInput
{
public string checkpoint_path;
public bool bf16 = true;
public bool torch_compile = false;
public int device_id = 0;
public string output_path; // ignored by server with above code
public float audio_duration;
public string prompt;
public string lyrics;
public int infer_step;
public float guidance_scale;
public string scheduler_type;
public string cfg_type;
public float omega_scale;
public List actual_seeds;
public float guidance_interval;
public float guidance_interval_decay;
public float min_guidance_scale;
public bool use_erg_tag;
public bool use_erg_lyric;
public bool use_erg_diffusion;
public List oss_steps;
public float guidance_scale_text = 0.0f;
public float guidance_scale_lyric = 0.0f;
}
[Serializable]
public class ACEStepOutput
{
public string status;
public string output_path; // filename returned by server
public string message;
}
public class ACEStepClient : MonoBehaviour
{
// Server base URL (no trailing slash)
public string serverBaseUrl = "http://localhost:8000";
if (isError)
{
Debug.LogError($"Error downloading audio file: {www.error}");
onError?.Invoke(www.error);
yield break;
}
byte[] audioData = www.downloadHandler.data;
// Check if directory exists, else create it
if (!Directory.Exists(unityOutputFolder))
{
Directory.CreateDirectory(unityOutputFolder);
}
string localPath = Path.Combine(unityOutputFolder, filename);
try
{
File.WriteAllBytes(localPath, audioData);
Debug.Log($"Audio file saved to {localPath}");
onComplete?.Invoke(localPath);
}
catch (Exception e)
{
Debug.LogError($"Failed to save audio file: {e.Message}");
onError?.Invoke(e.Message);
}
}
}
}
provide all edible things in the inspector I want to see them. also make it set a text mesh pro text to the filepath.
Certainly! I'll create a Unity MonoBehaviour script that has all editable fields from ACEStepInput exposed in the Inspector and also includes a reference to a TextMeshPro component. After the audio is generated and downloaded, it will update the TextMeshPro text with the local file path.
This script will use the provided ACEStepClient code internally but expose the inputs as Inspector fields for easy editing.
Notes:
Make sure you have TextMeshPro imported (using TMPro needed).
Attach this script to a GameObject in your scene.
Assign a TextMeshProUGUI or TextMeshPro component reference in the inspector.
The download folder will be Application.persistentDataPath + "/GeneratedAudio" by default.
The server URL is editable too.
csharp
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class ACEStepRuntimeInference : MonoBehaviour
{
[Header("Server Settings")]
[Tooltip("Base URL of the inference server (no trailing slash)")]
public string serverBaseUrl = "http://localhost:8000";
[Header("Input Parameters")]
public string checkpoint_path = "default_checkpoint.pt";
public bool bf16 = true;
public bool torch_compile = false;
public int device_id = 0;
[Tooltip("Ignored by server")]
public string output_path = ""; // We will not use, but kept for completeness
public float audio_duration = 10f;
[TextArea(2, 5)]
public string prompt = "This is a sample prompt.";
[TextArea(2, 5)]
public string lyrics = "";
public int infer_step = 50;
public float guidance_scale = 7.5f;
public string scheduler_type = "default";
public string cfg_type = "default";
public float omega_scale = 1.0f;
[Tooltip("Seeds for random generator")]
public List<int> actual_seeds = new List<int> { 42 };
public float guidance_interval = 1.0f;
public float guidance_interval_decay = 0.0f;
public float min_guidance_scale = 0.0f;
public bool use_erg_tag = false;
public bool use_erg_lyric = false;
public bool use_erg_diffusion = false;
[Tooltip("OSS steps")]
public List<int> oss_steps = new List<int> { 1, 2, 3 };
public float guidance_scale_text = 0.0f;
public float guidance_scale_lyric = 0.0f;
[Header("UI")]
[Tooltip("TextMeshPro Text component to display the saved filepath")]
public TMP_Text filePathText;
[Header("Output")]
[Tooltip("Local folder to save downloaded audio")]
public string localSaveFolder;
private ACEStepClient client;
void Awake()
{
// Make sure local save folder defaults to persistent data path + folder
if (string.IsNullOrEmpty(localSaveFolder))
{
localSaveFolder = System.IO.Path.Combine(Application.persistentDataPath, "GeneratedAudio");
}
// Add or find an ACEStepClient component on this GameObject for communication
client = GetComponent<ACEStepClient>();
if (client == null)
{
client = gameObject.AddComponent<ACEStepClient>();
}
client.serverBaseUrl = serverBaseUrl;
}
[ContextMenu("Start Generate Audio")]
public void StartGenerate()
{
ACEStepInput input = BuildACEStepInput();
client.GenerateAudio(input, OnGenerateSuccess, OnGenerateError);
}
private ACEStepInput BuildACEStepInput()
{
return new ACEStepInput()
{
checkpoint_path = checkpoint_path,
bf16 = bf16,
torch_compile = torch_compile,
device_id = device_id,
output_path = output_path,
audio_duration = audio_duration,
prompt = prompt,
lyrics = lyrics,
infer_step = infer_step,
guidance_scale = guidance_scale,
scheduler_type = scheduler_type,
cfg_type = cfg_type,
omega_scale = omega_scale,
actual_seeds = new List<int>(actual_seeds),
guidance_interval = guidance_interval,
guidance_interval_decay = guidance_interval_decay,
min_guidance_scale = min_guidance_scale,
use_erg_tag = use_erg_tag,
use_erg_lyric = use_erg_lyric,
use_erg_diffusion = use_erg_diffusion,
oss_steps = new List<int>(oss_steps),
guidance_scale_text = guidance_scale_text,
guidance_scale_lyric = guidance_scale_lyric,
};
}
private void OnGenerateSuccess(ACEStepOutput output)
{
Debug.Log("Generation success! Output path: " + output.output_path);
if (string.IsNullOrEmpty(output.output_path))
{
Debug.LogWarning("Output path from server is empty");
SetFilePathText("No output file returned from server");
return;
}
StartCoroutine(client.DownloadAndSaveAudio(output.output_path, localSaveFolder, OnDownloadComplete, OnDownloadError));
}
private void OnGenerateError(string error)
{
Debug.LogError("Generation failed: " + error);
SetFilePathText("Generation failed: " + error);
}
private void OnDownloadComplete(string localFullPath)
{
Debug.Log("Download and save completed: " + localFullPath);
SetFilePathText(localFullPath);
}
private void OnDownloadError(string error)
{
Debug.LogError("Download failed: " + error);
SetFilePathText("Download failed: " + error);
}
private void SetFilePathText(string text)
{
if (filePathText != null)
{
filePathText.text = text;
}
}
}
How to use:
Add this script to a GameObject (e.g., empty GameObject called ACEStepManager).
Drag your TextMeshProUGUI or TextMeshPro (3D) text component to the filePathText field.
Optionally adjust the server URL and input parameters.
At runtime, either call StartGenerate() from another script or press the context menu in the inspector (click the 3 dots on the component and select "Start Generate Audio").
After the audio is generated and downloaded, the filepath will be displayed on the assigned TextMeshPro text.
If you want, I can also prepare a simple UI or a button script to trigger this easily. Let me know!
I've cleaned out this but I want you to change this and give me the entire script fixed please
private void SetFilePathText(string text)
{
// I want you to add a viewable in inspector audio clip named 'Generation Result' put functionality in here to load the saved file into unity as an audio clip and set that clip to generation result
}
here is the entire script as it is.
using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
public class ACEStepRuntimeInference : MonoBehaviour
{
[Header("Server Settings")]
[Tooltip("Base URL of the inference server (no trailing slash)")]
public string serverBaseUrl = "http://localhost:8000";
code
[Header("Input Parameters")]
public string checkpoint_path = "default_checkpoint.pt";
public bool bf16 = true;
public bool torch_compile = false;
public int device_id = 0;
[Tooltip("Ignored by server")]
public string output_path = ""; // We will not use, but kept for completeness
public float audio_duration = 10f;
[TextArea(2, 5)]
public string prompt = "This is a sample prompt.";
[TextArea(2, 5)]
public string lyrics = "";
public int infer_step = 50;
public float guidance_scale = 7.5f;
public string scheduler_type = "default";
public string cfg_type = "default";
public float omega_scale = 1.0f;
[Tooltip("Seeds for random generator")]
public List<int> actual_seeds = new List<int> { 42 };
public float guidance_interval = 1.0f;
public float guidance_interval_decay = 0.0f;
public float min_guidance_scale = 0.0f;
public bool use_erg_tag = false;
public bool use_erg_lyric = false;
public bool use_erg_diffusion = false;
[Tooltip("OSS steps")]
public List<int> oss_steps = new List<int> { 1, 2, 3 };
public float guidance_scale_text = 0.0f;
public float guidance_scale_lyric = 0.0f;
[Header("Output")]
[Tooltip("Local folder to save downloaded audio")]
public string localSaveFolder;
private ACEStepClient client;
void Awake()
{
// Make sure local save folder defaults to persistent data path + folder
if (string.IsNullOrEmpty(localSaveFolder))
{
localSaveFolder = System.IO.Path.Combine(Application.persistentDataPath, "GeneratedAudio");
}
// Add or find an ACEStepClient component on this GameObject for communication
client = GetComponent<ACEStepClient>();
if (client == null)
{
client = gameObject.AddComponent<ACEStepClient>();
}
client.serverBaseUrl = serverBaseUrl;
}
[ContextMenu("Start Generate Audio")]
public void StartGenerate()
{
ACEStepInput input = BuildACEStepInput();
client.GenerateAudio(input, OnGenerateSuccess, OnGenerateError);
}
private ACEStepInput BuildACEStepInput()
{
return new ACEStepInput()
{
checkpoint_path = checkpoint_path,
bf16 = bf16,
torch_compile = torch_compile,
device_id = device_id,
output_path = output_path,
audio_duration = audio_duration,
prompt = prompt,
lyrics = lyrics,
infer_step = infer_step,
guidance_scale = guidance_scale,
scheduler_type = scheduler_type,
cfg_type = cfg_type,
omega_scale = omega_scale,
actual_seeds = new List<int>(actual_seeds),
guidance_interval = guidance_interval,
guidance_interval_decay = guidance_interval_decay,
min_guidance_scale = min_guidance_scale,
use_erg_tag = use_erg_tag,
use_erg_lyric = use_erg_lyric,
use_erg_diffusion = use_erg_diffusion,
oss_steps = new List<int>(oss_steps),
guidance_scale_text = guidance_scale_text,
guidance_scale_lyric = guidance_scale_lyric,
};
}
private void OnGenerateSuccess(ACEStepOutput output)
{
Debug.Log("Generation success! Output path: " + output.output_path);
if (string.IsNullOrEmpty(output.output_path))
{
Debug.LogWarning("Output path from server is empty");
SetFilePathText("No output file returned from server");
return;
}
StartCoroutine(client.DownloadAndSaveAudio(output.output_path, localSaveFolder, OnDownloadComplete, OnDownloadError));
}
private void OnGenerateError(string error)
{
Debug.LogError("Generation failed: " + error);
SetFilePathText("Generation failed: " + error);
}
private void OnDownloadComplete(string localFullPath)
{
Debug.Log("Download and save completed: " + localFullPath);
SetFilePathText(localFullPath);
}
private void OnDownloadError(string error)
{
Debug.LogError("Download failed: " + error);
SetFilePathText("Download failed: " + error);
}
private void SetFilePathText(string text)
{
}
}
Here's the fully fixed script with your requested changes implemented.
What I've done in SetFilePathText:
Made a public AudioClip field named GenerationResult visible in the inspector.
Added a method LoadAudioClipFromFile that uses UnityWebRequestMultimedia to load the saved local audio file into an AudioClip asynchronously.
When SetFilePathText is called with a valid path pointing to a file, it updates the TMP text and loads the file as an AudioClip assigned to GenerationResult.
Make sure your audio files are in a format Unity supports for UnityWebRequestMultimedia.GetAudioClip (e.g., wav, mp3, ogg).
csharp
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
public class ACEStepRuntimeInference : MonoBehaviour
{
[Header("Server Settings")]
[Tooltip("Base URL of the inference server (no trailing slash)")]
public string serverBaseUrl = "http://localhost:8000";
[Header("Input Parameters")]
public string checkpoint_path = "default_checkpoint.pt";
public bool bf16 = true;
public bool torch_compile = false;
public int device_id = 0;
[Tooltip("Ignored by server")]
public string output_path = ""; // We will not use, but kept for completeness
public float audio_duration = 10f;
[TextArea(2, 5)]
public string prompt = "This is a sample prompt.";
[TextArea(2, 5)]
public string lyrics = "";
public int infer_step = 50;
public float guidance_scale = 7.5f;
public string scheduler_type = "default";
public string cfg_type = "default";
public float omega_scale = 1.0f;
[Tooltip("Seeds for random generator")]
public List<int> actual_seeds = new List<int> { 42 };
public float guidance_interval = 1.0f;
public float guidance_interval_decay = 0.0f;
public float min_guidance_scale = 0.0f;
public bool use_erg_tag = false;
public bool use_erg_lyric = false;
public bool use_erg_diffusion = false;
[Tooltip("OSS steps")]
public List<int> oss_steps = new List<int> { 1, 2, 3 };
public float guidance_scale_text = 0.0f;
public float guidance_scale_lyric = 0.0f;
[Header("Output")]
[Tooltip("Local folder to save downloaded audio")]
public string localSaveFolder;
[Header("UI")]
[Tooltip("TextMeshPro Text component to display the saved filepath")]
public TMP_Text filePathText;
[Header("Generation Result")]
[Tooltip("AudioClip loaded from the generated audio file")]
public AudioClip GenerationResult;
private ACEStepClient client;
void Awake()
{
if (string.IsNullOrEmpty(localSaveFolder))
{
localSaveFolder = Path.Combine(Application.persistentDataPath, "GeneratedAudio");
}
client = GetComponent<ACEStepClient>();
if (client == null)
{
client = gameObject.AddComponent<ACEStepClient>();
}
client.serverBaseUrl = serverBaseUrl;
}
[ContextMenu("Start Generate Audio")]
public void StartGenerate()
{
ACEStepInput input = BuildACEStepInput();
client.GenerateAudio(input, OnGenerateSuccess, OnGenerateError);
}
private ACEStepInput BuildACEStepInput()
{
return new ACEStepInput()
{
checkpoint_path = checkpoint_path,
bf16 = bf16,
torch_compile = torch_compile,
device_id = device_id,
output_path = output_path,
audio_duration = audio_duration,
prompt = prompt,
lyrics = lyrics,
infer_step = infer_step,
guidance_scale = guidance_scale,
scheduler_type = scheduler_type,
cfg_type = cfg_type,
omega_scale = omega_scale,
actual_seeds = new List<int>(actual_seeds),
guidance_interval = guidance_interval,
guidance_interval_decay = guidance_interval_decay,
min_guidance_scale = min_guidance_scale,
use_erg_tag = use_erg_tag,
use_erg_lyric = use_erg_lyric,
use_erg_diffusion = use_erg_diffusion,
oss_steps = new List<int>(oss_steps),
guidance_scale_text = guidance_scale_text,
guidance_scale_lyric = guidance_scale_lyric,
};
}
private void OnGenerateSuccess(ACEStepOutput output)
{
Debug.Log("Generation success! Output path: " + output.output_path);
if (string.IsNullOrEmpty(output.output_path))
{
Debug.LogWarning("Output path from server is empty");
SetFilePathText("No output file returned from server");
return;
}
StartCoroutine(client.DownloadAndSaveAudio(output.output_path, localSaveFolder, OnDownloadComplete, OnDownloadError));
}
private void OnGenerateError(string error)
{
Debug.LogError("Generation failed: " + error);
SetFilePathText("Generation failed: " + error);
}
private void OnDownloadComplete(string localFullPath)
{
Debug.Log("Download and save completed: " + localFullPath);
SetFilePathText(localFullPath);
}
private void OnDownloadError(string error)
{
Debug.LogError("Download failed: " + error);
SetFilePathText("Download failed: " + error);
}
private void SetFilePathText(string text)
{
if (filePathText != null)
{
filePathText.text = text;
}
// If the path is a valid existing file, try to load it as an AudioClip
if (!string.IsNullOrEmpty(text) && File.Exists(text))
{
StartCoroutine(LoadAudioClipFromFile(text));
}
else
{
// Clear the audio clip if path invalid or error message
GenerationResult = null;
}
}
private IEnumerator LoadAudioClipFromFile(string filePath)
{
if (!File.Exists(filePath))
{
Debug.LogError($"Audio file not found on disk: {filePath}");
GenerationResult = null;
yield break;
}
// We use file:// URI scheme for local files
string uri = "file://" + filePath;
// Detect audio type by extension
AudioType audioType = GetAudioTypeFromFileExtension(filePath);
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(uri, audioType))
{
yield return www.SendWebRequest();
#if UNITY_2020_1_OR_NEWER
bool isError = www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError;
#else
bool isError = www.isNetworkError || www.isHttpError;
#endif
if (isError)
{
Debug.LogError($"Failed to load audio clip from file: {www.error}");
GenerationResult = null;
}
else
{
AudioClip clip = DownloadHandlerAudioClip.GetContent(www);
if (clip == null)
{
Debug.LogError("Loaded AudioClip is null");
GenerationResult = null;
}
else
{
Debug.Log($"AudioClip loaded successfully from {filePath}");
GenerationResult = clip;
}
}
}
}
private AudioType GetAudioTypeFromFileExtension(string filePath)
{
string extension = Path.GetExtension(filePath).ToLowerInvariant();
switch (extension)
{
case ".wav": return AudioType.WAV;
case ".mp3": return AudioType.MPEG;
case ".ogg": return AudioType.OGGVORBIS;
case ".aiff": return AudioType.AIFF;
case ".mod": return AudioType.MOD;
case ".xm": return AudioType.XM;
case ".it": return AudioType.IT;
case ".s3m": return AudioType.S3M;
default:
Debug.LogWarning($"Unknown audio file extension '{extension}', defaulting to WAV");
return AudioType.WAV;
}
}
}
Summary:
GenerationResult is shown in inspector and updated with the downloaded audio clip.
The TMP text always shows the current file path or error message.
Unity's UnityWebRequestMultimedia is used to load the local audio file asynchronously.
Your existing ACEStepClient component remains unchanged and handles generation and download.
Let me know if you want help on playing the generated audio directly in-game or UI to trigger generation!
remove text mesh pro stuff from the script and send the script back fully ty
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
public class ACEStepRuntimeInference : MonoBehaviour
{
[Header("Server Settings")]
[Tooltip("Base URL of the inference server (no trailing slash)")]
public string serverBaseUrl = "http://localhost:8000";
code
[Header("Input Parameters")]
public string checkpoint_path = "default_checkpoint.pt";
public bool bf16 = true;
public bool torch_compile = false;
public int device_id = 0;
[Tooltip("Ignored by server")]
public string output_path = ""; // We will not use, but kept for completeness
public float audio_duration = 10f;
[TextArea(2, 5)]
public string prompt = "This is a sample prompt.";
[TextArea(2, 5)]
public string lyrics = "";
public int infer_step = 50;
public float guidance_scale = 7.5f;
public string scheduler_type = "default";
public string cfg_type = "default";
public float omega_scale = 1.0f;
[Tooltip("Seeds for random generator")]
public List<int> actual_seeds = new List<int> { 42 };
public float guidance_interval = 1.0f;
public float guidance_interval_decay = 0.0f;
public float min_guidance_scale = 0.0f;
public bool use_erg_tag = false;
public bool use_erg_lyric = false;
public bool use_erg_diffusion = false;
[Tooltip("OSS steps")]
public List<int> oss_steps = new List<int> { 1, 2, 3 };
public float guidance_scale_text = 0.0f;
public float guidance_scale_lyric = 0.0f;
[Header("Output")]
[Tooltip("Local folder to save downloaded audio")]
public string localSaveFolder;
[Header("UI")]
[Tooltip("TextMeshPro Text component to display the saved filepath")]
public TMP_Text filePathText;
[Header("Generation Result")]
[Tooltip("AudioClip loaded from the generated audio file")]
public AudioClip GenerationResult;
private ACEStepClient client;
void Awake()
{
if (string.IsNullOrEmpty(localSaveFolder))
{
localSaveFolder = Path.Combine(Application.persistentDataPath, "GeneratedAudio");
}
client = GetComponent<ACEStepClient>();
if (client == null)
{
client = gameObject.AddComponent<ACEStepClient>();
}
client.serverBaseUrl = serverBaseUrl;
}
[ContextMenu("Start Generate Audio")]
public void StartGenerate()
{
ACEStepInput input = BuildACEStepInput();
client.GenerateAudio(input, OnGenerateSuccess, OnGenerateError);
}
private ACEStepInput BuildACEStepInput()
{
return new ACEStepInput()
{
checkpoint_path = checkpoint_path,
bf16 = bf16,
torch_compile = torch_compile,
device_id = device_id,
output_path = output_path,
audio_duration = audio_duration,
prompt = prompt,
lyrics = lyrics,
infer_step = infer_step,
guidance_scale = guidance_scale,
scheduler_type = scheduler_type,
cfg_type = cfg_type,
omega_scale = omega_scale,
actual_seeds = new List<int>(actual_seeds),
guidance_interval = guidance_interval,
guidance_interval_decay = guidance_interval_decay,
min_guidance_scale = min_guidance_scale,
use_erg_tag = use_erg_tag,
use_erg_lyric = use_erg_lyric,
use_erg_diffusion = use_erg_diffusion,
oss_steps = new List<int>(oss_steps),
guidance_scale_text = guidance_scale_text,
guidance_scale_lyric = guidance_scale_lyric,
};
}
private void OnGenerateSuccess(ACEStepOutput output)
{
Debug.Log("Generation success! Output path: " + output.output_path);
if (string.IsNullOrEmpty(output.output_path))
{
Debug.LogWarning("Output path from server is empty");
SetFilePathText("No output file returned from server");
return;
}
StartCoroutine(client.DownloadAndSaveAudio(output.output_path, localSaveFolder, OnDownloadComplete, OnDownloadError));
}
private void OnGenerateError(string error)
{
Debug.LogError("Generation failed: " + error);
SetFilePathText("Generation failed: " + error);
}
private void OnDownloadComplete(string localFullPath)
{
Debug.Log("Download and save completed: " + localFullPath);
SetFilePathText(localFullPath);
}
private void OnDownloadError(string error)
{
Debug.LogError("Download failed: " + error);
SetFilePathText("Download failed: " + error);
}
private void SetFilePathText(string text)
{
if (filePathText != null)
{
filePathText.text = text;
}
// If the path is a valid existing file, try to load it as an AudioClip
if (!string.IsNullOrEmpty(text) && File.Exists(text))
{
StartCoroutine(LoadAudioClipFromFile(text));
}
else
{
// Clear the audio clip if path invalid or error message
GenerationResult = null;
}
}
private IEnumerator LoadAudioClipFromFile(string filePath)
{
if (!File.Exists(filePath))
{
Debug.LogError($"Audio file not found on disk: {filePath}");
GenerationResult = null;
yield break;
}
// We use file:// URI scheme for local files
string uri = "file://" + filePath;
// Detect audio type by extension
AudioType audioType = GetAudioTypeFromFileExtension(filePath);
using (UnityWebRequest www = UnityWebRequestMultimedia.GetAudioClip(uri, audioType))
{
yield return www.SendWebRequest();