Error: Cannot create FMOD::Sound instance for clip "" (FMOD error: Error loading file. ) #90
-
Bug ReportOverview
To ReproduceSteps to reproduce the behavior: The first request I make works just fine, but any continued requests throw this error. When I stop and start the game again, it works the first time. |
Beta Was this translation helpful? Give feedback.
Replies: 11 comments
-
Need a code snippet for repro steps |
Beta Was this translation helpful? Give feedback.
-
It is generating mp3 or PCM? |
Beta Was this translation helpful? Give feedback.
-
This is my ElevenLabsManager.cs script: using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using ElevenLabs;
using System.Threading.Tasks;
using System.Threading;
using Utilities.Async;
public class ElevenLabsManager : MonoBehaviour
{
// Singleton instance
public static ElevenLabsManager Instance { get; private set; }
private string elevenLabsAPIKey;
private ElevenLabsClient api;
private void Awake()
{
// Ensure there's only one instance of AIManager
if (Instance == null)
{
Instance = this;
//DontDestroyOnLoad(gameObject); // Optional: Keep this instance between scene loads
}
else
{
Destroy(gameObject);
}
}
void Start()
{
// Get the API key set in the user's environment variables
elevenLabsAPIKey = Environment.GetEnvironmentVariable("ELEVEN_LABS_API_KEY", EnvironmentVariableTarget.User);
Debug.Log(elevenLabsAPIKey);
if (!string.IsNullOrEmpty(elevenLabsAPIKey))
{
Debug.Log("API Key found: " + elevenLabsAPIKey);
// Use the API key in your requests or other logic
}
else
{
Debug.LogError("API Key not found!");
}
// Initialize the ElevenLabs API Client
api = new ElevenLabsClient(elevenLabsAPIKey);
if (api == null)
{
Debug.LogError("ElevenLabsClient could not be initialized.");
}
}
// Function to generate an audio clip from text and voiceId
public async Task<AudioClip> GenerateAudioClip(string text, string voiceId)
{
try
{
// Fetch the voice using the voiceId
var voice = await api.VoicesEndpoint.GetVoiceAsync(voiceId);
if (voice == null)
{
Debug.LogError("Voice not found with the given voiceId.");
return null;
}
// Fetch the default voice settings
var defaultVoiceSettings = await api.VoicesEndpoint.GetDefaultVoiceSettingsAsync();
if (defaultVoiceSettings == null)
{
Debug.LogError("Default voice settings could not be retrieved.");
return null;
}
// Generate the AudioClip using the TextToSpeech API
var voiceClip = await api.TextToSpeechEndpoint.TextToSpeechAsync(text, voice, defaultVoiceSettings);
return voiceClip.AudioClip;
}
catch (System.Exception ex)
{
Debug.LogError($"Error generating audio clip: {ex.Message}");
return null;
}
}
}
I am making calls to it like so: AIUser.cs // Text to speech- I accidently named this function SpeechToText. Will need to fix this, but inform others to change their function name in their scripts.
public async void SpeechToText(string text)
{
AudioClip clip;
if (characterData.usingOnlineTTS == false)
{
clip = await AIManager.Instance.GetTextToSpeech(text, characterData.speakerID);
}
else
{
clip = await AIManager.Instance.GetElevenLabsAudioClip(text, characterData.elevenLabsModelID);
}
audioSource.clip = clip;
audioSource.loop = false;
audioSource.Play();
} AIManager.cs // *** ONLINE TEXT TO SPEECH FUNCTIONS ***
// Function to get audio clip from ElevenLabs using ElevenLabsManager
public async Task<AudioClip> GetElevenLabsAudioClip(string text, string voiceId)
{
try
{
// Use the ElevenLabsManager's GenerateAudioClip function to get the audio clip
AudioClip clip = await ElevenLabsManager.Instance.GenerateAudioClip(text, voiceId);
return clip;
}
catch (System.Exception ex)
{
Debug.LogError($"Error in GetElevenLabsAudioClip: {ex.Message}");
return null;
}
} AIUser -> AIManager -> ElevenLabsManager I greatly appreciate you responding so quickly! |
Beta Was this translation helpful? Give feedback.
-
What happens when you run the sample scene? |
Beta Was this translation helpful? Give feedback.
-
Usually this should only happen in this context #35 |
Beta Was this translation helpful? Give feedback.
-
The sample scene seems to run with no issues. I noticed you used audioSource.PlayOneShot(), and so I changed the end of my AIUser function to this: // Text to speech- I accidently named this function SpeechToText. Will need to fix this, but inform others to change their function name in their scripts.
public async void SpeechToText(string text)
{
AudioClip clip;
if (characterData.usingOnlineTTS == false)
{
clip = await AIManager.Instance.GetTextToSpeech(text, characterData.speakerID);
}
else
{
clip = await AIManager.Instance.GetElevenLabsAudioClip(text, characterData.elevenLabsModelID);
}
//audioSource.clip = clip;
//audioSource.loop = false;
audioSource.PlayOneShot(clip);
} And I seem to be getting no errors now. Could that possibly be it!? I only changed the last three lines of that function. |
Beta Was this translation helpful? Give feedback.
The sample scene seems to run with no issues.
I noticed you used audioSource.PlayOneShot(), and so I changed the end of my AIUser function to this: