hi please edit my script and send back the full script edited, it works fine but I want to be able to show the resulting audio file inside of the window and the ability to play it there.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using UnityEditor;
using UnityEngine;

public class OAS1MEditorWindow : EditorWindow
{
    // Params
    private string _url = "http://127.0.0.1:8032/v1/tts";
    private string _text = "(excited) Thank you for your perchase! (happy) I hope you enjoy it.";
    private string _apiKey = "YOUR_API_KEY_HERE"; // Only required if you're connecting to someone else's server.

    private enum AudioFormat { WAV, MP3 }
    private AudioFormat _format = AudioFormat.WAV;

    private int chunkLength = 0;
    private int maxNewTokens = 0;
    private float topP = 0.9f;
    private float temperature = 0.9f;
    private float repetitionPenalty = 1.1f;

    private enum SeedMode { Random, Fixed }
    private SeedMode seedMode = SeedMode.Random;
    private int seed = 0;

    private bool normalize = false;
    private bool streaming = false;
    private string use_memory_cache = "off";

    // Changed types here
    private List<TextAsset> referenceTextAssets = new List<TextAsset> { null };
    private List<AudioClip> referenceAudioClips = new List<AudioClip> { null };

    private DefaultAsset outputFolder; // The Unity project folder chosen
    private string outputFileName = "output"; // filename without extension

    private Vector2 scroll;
    private Vector2 textScrollPos; // Scroll position for multiline text area

    private Texture2D logoTexture;

    [MenuItem("Tools/OAS1M TTS")]
    public static void ShowWindow()
    {
        var window = GetWindow<OAS1MEditorWindow>("OAS1M TTS");
        window.minSize = new Vector2(400, 650);
    }

    private void OnEnable()
    {
        // Default output folder = "Assets"
        outputFolder = AssetDatabase.LoadAssetAtPath<DefaultAsset>("Assets");
        outputFileName = "output";
        LoadLogo();
    }

    void LoadLogo()
    {
        // Load a logo from Resources folder (place your logo as Assets/Resources/oas1m_logo.png)
        logoTexture = Resources.Load<Texture2D>("oas1m_logo");
    }

    private void OnGUI()
    {
        scroll = EditorGUILayout.BeginScrollView(scroll);

        GUILayout.Space(10);

        if (logoTexture != null)
        {
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.Label(logoTexture, GUILayout.Width(256), GUILayout.Height(128));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
        }

        GUILayout.Space(10);
        EditorGUILayout.LabelField("TTS Configuration", EditorStyles.boldLabel);
        EditorGUILayout.Space();

        _url = EditorGUILayout.TextField("URL", _url);

        // Multiline text input with scrollbars
        EditorGUILayout.LabelField("Text");
        float textAreaHeight = 100; // Adjust height as needed
        textScrollPos = EditorGUILayout.BeginScrollView(textScrollPos, GUILayout.Height(textAreaHeight));
        _text = EditorGUILayout.TextArea(_text, GUILayout.ExpandHeight(true));
        EditorGUILayout.EndScrollView();

        _apiKey = EditorGUILayout.TextField("API Key", _apiKey);

        // Format dropdown
        _format = (AudioFormat)EditorGUILayout.EnumPopup("Format", _format);

        chunkLength = EditorGUILayout.IntField("Chunk Length", chunkLength);
        maxNewTokens = EditorGUILayout.IntField("Max New Tokens", maxNewTokens);
        topP = EditorGUILayout.Slider("Top P", topP, 0f, 1f);
        temperature = EditorGUILayout.Slider("Temperature", temperature, 0f, 2f);
        repetitionPenalty = EditorGUILayout.FloatField("Repetition Penalty", repetitionPenalty);

        // Seed mode dropdown + seed input (only enabled if Fixed)
        seedMode = (SeedMode)EditorGUILayout.EnumPopup("Seed Mode", seedMode);
        using (new EditorGUI.DisabledScope(seedMode == SeedMode.Random))
        {
            seed = EditorGUILayout.IntField("Seed Value", seed);
        }

        EditorGUILayout.Space();

        // Missing parameters GUI
        normalize = EditorGUILayout.Toggle("Normalize", normalize);
        streaming = EditorGUILayout.Toggle("Streaming", streaming);

        // use_memory_cache dropdown
        string[] cacheOptions = new string[] { "off", "on" };
        int currentCacheIndex = Array.IndexOf(cacheOptions, use_memory_cache);
        if (currentCacheIndex < 0) currentCacheIndex = 0;
        int selectedCache = EditorGUILayout.Popup("Use Memory Cache", currentCacheIndex, cacheOptions);
        use_memory_cache = cacheOptions[selectedCache];

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Reference Text Assets", EditorStyles.boldLabel);
        int removeTextIndex = -1;
        for (int i = 0; i < referenceTextAssets.Count; i++)
        {
            GUILayout.BeginHorizontal();
            referenceTextAssets[i] = (TextAsset)EditorGUILayout.ObjectField(referenceTextAssets[i], typeof(TextAsset), false);
            if (GUILayout.Button("X", GUILayout.Width(20))) removeTextIndex = i;
            GUILayout.EndHorizontal();
        }
        if (removeTextIndex >= 0)
        {
            referenceTextAssets.RemoveAt(removeTextIndex);
            if (referenceAudioClips.Count > removeTextIndex)
                referenceAudioClips.RemoveAt(removeTextIndex);
        }
        if (GUILayout.Button("+ Add Reference Text"))
        {
            referenceTextAssets.Add(null);
            referenceAudioClips.Add(null);
        }

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Reference Audio Clips", EditorStyles.boldLabel);
        for (int i = 0; i < referenceAudioClips.Count; i++)
        {
            GUILayout.BeginHorizontal();
            referenceAudioClips[i] = (AudioClip)EditorGUILayout.ObjectField(referenceAudioClips[i], typeof(AudioClip), false);
            if (GUILayout.Button("Clear", GUILayout.Width(50)))
            {
                referenceAudioClips[i] = null;
            }
            GUILayout.EndHorizontal();
        }

        EditorGUILayout.Space();

        EditorGUILayout.LabelField("Output Folder (project folder)", EditorStyles.boldLabel);
        outputFolder = (DefaultAsset)EditorGUILayout.ObjectField(outputFolder, typeof(DefaultAsset), false);

        EditorGUILayout.LabelField("Output Filename (without extension)", EditorStyles.boldLabel);
        outputFileName = EditorGUILayout.TextField(outputFileName);

        GUILayout.Space(20);

        if (GUILayout.Button("Generate Audio", GUILayout.Height(40)))
        {
            _ = GenerateAudioAsync();
        }

        EditorGUILayout.EndScrollView();
    }

    private async Task GenerateAudioAsync()
    {
        if (referenceTextAssets.Count != referenceAudioClips.Count)
        {
            UnityEngine.Debug.LogError("Reference texts and reference audios counts do not match.");
            EditorUtility.DisplayDialog("Error", "Reference Text Assets and Reference Audio Clips count mismatch.", "OK");
            return;
        }

        // Resolve output folder path in filesystem:
        string folderPath = AssetDatabase.GetAssetPath(outputFolder);
        if (string.IsNullOrEmpty(folderPath) || !Directory.Exists(folderPath))
        {
            EditorUtility.DisplayDialog("Error", "Output folder is invalid or does not exist.", "OK");
            return;
        }

        // Compose full output path
        string extension = _format.ToString().ToLower();
        if (!extension.StartsWith("."))
            extension = "." + extension;
        string outputFilePath = Path.Combine(folderPath, outputFileName + extension);

        // Convert TextAssets to strings
        List<string> referenceTexts = new List<string>(referenceTextAssets.Count);
        for (int i = 0; i < referenceTextAssets.Count; i++)
        {
            if (referenceTextAssets[i] != null)
                referenceTexts.Add(referenceTextAssets[i].text);
            else
                referenceTexts.Add(string.Empty);
        }

        // Convert AudioClips to byte arrays
        List<byte[]> referenceAudios = new List<byte[]>(referenceAudioClips.Count);
        for (int i = 0; i < referenceAudioClips.Count; i++)
        {
            AudioClip clip = referenceAudioClips[i];
            if (clip != null)
            {
                try
                {
                    byte[] wavData = AudioClipToWav(clip);
                    referenceAudios.Add(wavData);
                }
                catch (Exception ex)
                {
                    UnityEngine.Debug.LogError($"Failed to convert AudioClip '{clip.name}' to WAV bytes: {ex.Message}");
                    referenceAudios.Add(null);
                }
            }
            else
            {
                referenceAudios.Add(null);
            }
        }

        // Handle seed generation based on seed mode
        if (seedMode == SeedMode.Random)
        {
            seed = new System.Random().Next(int.MinValue, int.MaxValue);
        }
        // else use fixed seed from user input

        var client = new TTSClient(
            url: _url,
            text: _text,
            apiKey: _apiKey,
            referenceTexts: referenceTexts,
            referenceAudios: referenceAudios,
            format: extension.TrimStart('.'),
            chunkLength: chunkLength,
            topP: topP,
            temperature: temperature,
            seed: seed,
            maxNewTokens: maxNewTokens,
            repetitionPenalty: repetitionPenalty,
            outputFilePath: outputFilePath,
            normalize: normalize,
            streaming: streaming,
            use_memory_cache: use_memory_cache
            );

        EditorUtility.DisplayProgressBar("OAS1M", "Sending TTS request...", 0.5f);
        var (success, message) = await client.SendRequestAndSaveAudioAsync();
        EditorUtility.ClearProgressBar();

        if (success)
        {
            AssetDatabase.Refresh(); // Refresh the AssetDatabase to show the new file if inside Assets folder or subfolder
            UnityEngine.Debug.Log("TTS audio saved: " + message);

            // Instead of revealing in OS file browser, select and ping the asset in Unity Editor
            if (File.Exists(message))
            {
                // Convert absolute file path to relative project path
                string assetPath = GetAssetPathFromFullPath(message);
                if (!string.IsNullOrEmpty(assetPath))
                {
                    UnityEngine.Object asset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetPath);
                    if (asset != null)
                    {
                        Selection.activeObject = asset;
                        EditorGUIUtility.PingObject(asset);
                    }
                    else
                    {
                        UnityEngine.Debug.LogWarning($"{assetPath} exists but could not load asset in Unity.");
                    }
                }
                else
                {
                    UnityEngine.Debug.LogWarning($"Generated file is outside the Unity project Assets folder and cannot be shown in the Project window.");
                }
            }
        }
        else
        {
            EditorUtility.DisplayDialog("Failure", message, "OK");
            UnityEngine.Debug.LogError("TTS failed: " + message);
        }
    }

    /// <summary>
    /// Converts full absolute path to relative Unity asset path starting from "Assets/"
    /// Returns null if file is outside Assets folder.
    /// </summary>
    /// <param name="fullPath">Absolute file path</param>
    /// <returns>Relative path or null</returns>
    private string GetAssetPathFromFullPath(string fullPath)
    {
        string projectPath = Application.dataPath; // absolute path to Assets folder
        // Normalize slashes for safety
        fullPath = Path.GetFullPath(fullPath).Replace('\\', '/');
        projectPath = Path.GetFullPath(projectPath).Replace('\\', '/');

        if (fullPath.StartsWith(projectPath))
        {
            // +1 to include 'Assets' folder name (relative path starts with "Assets/")
            string relativePath = "Assets" + fullPath.Substring(projectPath.Length);
            return relativePath;
        }
        return null;
    }

    /// <summary>
    /// Converts an AudioClip to a WAV byte array.
    /// This method encodes the AudioClip samples into a WAV file format in memory.
    /// </summary>
    /// <param name="clip">AudioClip to convert.</param>
    /// <returns>WAV file content as byte array.</returns>
    private byte[] AudioClipToWav(AudioClip clip)
    {
        if (clip == null)
            throw new ArgumentNullException(nameof(clip));

        // Get raw audio samples
        float[] samples = new float[clip.samples * clip.channels];
        clip.GetData(samples, 0);

        // Convert float samples [-1..1] to 16-bit PCM data
        byte[] pcmData = new byte[samples.Length * 2];
        int rescaleFactor = 32767; // to convert float to Int16

        for (int i = 0; i < samples.Length; i++)
        {
            short intData = (short)(samples[i] * rescaleFactor);
            pcmData[i * 2] = (byte)(intData & 0xff);
            pcmData[i * 2 + 1] = (byte)((intData >> 8) & 0xff);
        }

        using (MemoryStream memoryStream = new MemoryStream())
        using (BinaryWriter writer = new BinaryWriter(memoryStream))
        {
            int sampleRate = clip.frequency;
            int channels = clip.channels;
            int byteRate = sampleRate * channels * 2; // 16 bit

            // RIFF header
            writer.Write(System.Text.Encoding.ASCII.GetBytes("RIFF"));
            writer.Write(36 + pcmData.Length); // file size minus 8 bytes
            writer.Write(System.Text.Encoding.ASCII.GetBytes("WAVE"));

            // fmt subchunk
            writer.Write(System.Text.Encoding.ASCII.GetBytes("fmt "));
            writer.Write(16); // Subchunk1Size (16 for PCM)
            writer.Write((short)1); // AudioFormat (1 = PCM)
            writer.Write((short)channels);
            writer.Write(sampleRate);
            writer.Write(byteRate);
            writer.Write((short)(channels * 2)); // BlockAlign
            writer.Write((short)16); // BitsPerSample

            // data subchunk
            writer.Write(System.Text.Encoding.ASCII.GetBytes("data"));
            writer.Write(pcmData.Length);
            writer.Write(pcmData);

            writer.Flush();
            return memoryStream.ToArray();
        }
    }
}