Adventure Creator Wikia
Explore
Main Page
Discuss
All Pages
Community
Interactive Maps
Recent Blog Posts
Popular pages
Most visited articles
Custom Action - Variable: MultiBoolCheck
General
Scrolling text and Scrolling text audio.
Cancel Interaction Menus
Adding image effects
Custom trigger (triggers one actionlist when entering and another when exiting)
Randomize speech audio (Random Syllables)
Use items on an AC Character
Running Animations when game is paused
Integrations
CNControls Integration (Virtual Joystick)
Rewired integration
Unity analytics Integration (AC Action)
FinalIK Interactions Integration (AC Action)
Rogo Lipsync (No audio) 01 - Play Action
Rogo Lipsync (No audio) 02 - Stop Action
Rogo Lipsync (No audio) 03 - Set Emotion Action
FANDOM
Fan Central
BETA
Games
Anime
Movies
TV
Video
Wikis
Explore Wikis
Community Central
Start a Wiki
Don't have an account?
Register
Sign In
Sign In
Register
Adventure Creator Wikia
192
pages
Explore
Main Page
Discuss
All Pages
Community
Interactive Maps
Recent Blog Posts
Popular pages
Most visited articles
Custom Action - Variable: MultiBoolCheck
General
Scrolling text and Scrolling text audio.
Cancel Interaction Menus
Adding image effects
Custom trigger (triggers one actionlist when entering and another when exiting)
Randomize speech audio (Random Syllables)
Use items on an AC Character
Running Animations when game is paused
Integrations
CNControls Integration (Virtual Joystick)
Rewired integration
Unity analytics Integration (AC Action)
FinalIK Interactions Integration (AC Action)
Rogo Lipsync (No audio) 01 - Play Action
Rogo Lipsync (No audio) 02 - Stop Action
Rogo Lipsync (No audio) 03 - Set Emotion Action
Editing
Auto-assign custom speech audio
Back to page
Edit
Edit source
View history
Talk (0)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
The "Auto-name speech audio files?" option in the Speech Manager lets you toggle between having speech audio referred to manually, or automatically through naming convention. When unchecked, audio file fields are exposed in the Speech Manager for each line, and the user can manually assign an AudioClip.Β When checked, the audio is pulled at runtime from the Resources folder, provided that its location and filename matches its expected value. For example, the Demo game's Player lines are audio files of the format: /Resources/Speech/Brain39 This script lets you toggle between the two modes more easily, should audio files have already been assigned.Β If your audio is currently manually-set, this script will rename and move the files into a Resources folder.Β If automatically-set, it can manually link clips to each entry in the Speech Manager so that they can be moved out of the Resources folder. To use, paste the code below into a C# script named CustomAudioManagement.cs, and place the file in a folder named Editor somewhere in your Project window. You can then use the new links under "Adventure Creator -> Speech audio management" in the top toolbar. using System.Collections;<br> using System.Collections.Generic;<br> using UnityEngine;<br> using UnityEditor;<br> using AC;<br> <br> public class CustomAudioManagement : MonoBehaviour<br> {<br> <br> [MenuItem ("Adventure Creator/Speech audio management/Assign Resources audio manually", false, 39)]<br> static void AutoAssignAudio ()<br> {<br> if (EditorUtility.DisplayDialog ("Auto-assign audio", "This script will locate all 'Resources' speech audio files and assign them manually to their associated entry in the Speech Manager. It is recommended to backup your project beforehand. Continue?", "OK", "Cancel"))<br> {<br> bool overwrite = UnityEditor.EditorUtility.DisplayDialog ("Overwrite fields?", "If a line entry is found to already have audio manually assigned, should this process overwrite it?", "Yes", "No");<br> if (AdvGame.GetReferences ().speechManager)<br> {<br> SpeechManager speechManager = AdvGame.GetReferences ().speechManager;<br> speechManager.autoNameSpeechFiles = false;<br> <br> int numAssigned = 0;<br> for (int i=0; i<speechManager.lines.Count; i++)<br> {<br> EditorUtility.DisplayProgressBar ("Renaming files..", "Please wait while the operation completes.", (float) (i) / (float) speechManager.lines.Count);<br> <br> SpeechLine line = speechManager.lines[i];<br> if (line.textType == AC_TextType.Speech)<br> {<br> int lineNumUpdated = AssignAudioManually (speechManager, line, overwrite);<br> numAssigned += lineNumUpdated;<br> }<br> }<br> <br> EditorUtility.ClearProgressBar ();<br> EditorUtility.DisplayDialog ("Auto-assign audio", "Process complete. " + numAssigned + " lines were updated. The linked audio files can now be moved out of the Resources folder.", "OK");<br> }<br> else<br> {<br> Debug.LogWarning ("No Speech Manager assigned");<br> }<br> }<br> }<br> <br> <br> private static int AssignAudioManually (SpeechManager speechManager, SpeechLine line, bool overwrite)<br> {<br> int numUpdated = 0;<br> if (AssignAudioManually (speechManager, line, 0, overwrite))<br> {<br> numUpdated ++;<br> }<br> <br> if (speechManager.languages != null && speechManager.languages.Count > 1 && speechManager.translateAudio)<br> {<br> for (int i=1; i<speechManager.languages.Count; i++)<br> {<br> if (AssignAudioManually (speechManager, line, i, overwrite))<br> {<br> numUpdated ++;<br> }<br> }<br> }<br> <br> return numUpdated;<br> }<br> <br> <br> private static bool AssignAudioManually (SpeechManager speechManager, SpeechLine line, int languageIndex, bool overwrite)<br> {<br> string languageName = (languageIndex <= 0) ? string.Empty : speechManager.languages[languageIndex];<br> <br> string fullFilename = KickStarter.speechManager.GetAutoAssetPathAndName (line.lineID, null, languageName, false);<br> <br> AudioClip clipObj = Resources.Load (fullFilename) as AudioClip;<br> if (clipObj != null)<br> {<br> if (languageIndex > 0)<br> {<br> if (line.customTranslationAudioClips != null && line.customTranslationAudioClips.Count > (languageIndex-1))<br> {<br> if (line.customTranslationAudioClips[languageIndex-1] == null || overwrite)<br> {<br> line.customTranslationAudioClips[languageIndex-1] = clipObj;<br> }<br> }<br> }<br> else<br> {<br> if (line.customAudioClip == null || overwrite)<br> {<br> line.customAudioClip = clipObj;<br> }<br> }<br> <br> return true;<br> }<br> return false;<br> }<br> <br> <br> [MenuItem ("Adventure Creator/Speech audio management/Rename manual audio to automatic", false, 40)]<br> static void RenameManualAudio ()<br> {<br> if (EditorUtility.DisplayDialog ("Rename manual audio", "This script will locate all audio files manually assigned in the Speech Manager, and rename them to the convention expected when 'Auto-name audio files?' is checked. The files will not be moved, so must still be placed in the appropriate Resources/Speech subfolder. Continue?", "OK", "Cancel"))<br> {<br> bool move = UnityEditor.EditorUtility.DisplayDialog ("Move files?", "When complete, audio files will need to be located in a Resources/Speech subfolder. Do you want renamed files to be moved automatically?", "Yes", "No");<br> if (AdvGame.GetReferences ().speechManager)<br> {<br> SpeechManager speechManager = AdvGame.GetReferences ().speechManager;<br> <br> if (string.IsNullOrEmpty (speechManager.autoSpeechFolder))<br> {<br> speechManager.autoSpeechFolder = "Speech";<br> }<br> <br> if (move)<br> {<br> if (!AssetDatabase.IsValidFolder ("Assets/Resources"))<br> {<br> AssetDatabase.CreateFolder ("Assets", "Resources");<br> }<br> <br> if (!AssetDatabase.IsValidFolder ("Assets/Resources/" + speechManager.autoSpeechFolder))<br> {<br> AssetDatabase.CreateFolder ("Assets/Resources", speechManager.autoSpeechFolder);<br> }<br> }<br> <br> speechManager.autoNameSpeechFiles = true;<br> speechManager.placeAudioInSubfolders = true;<br> <br> int numAssigned = 0;<br> for (int i=0; i<speechManager.lines.Count; i++)<br> {<br> EditorUtility.DisplayProgressBar ("Renaming files..", "Please wait while the operation completes.", (float) (i) / (float) speechManager.lines.Count);<br> <br> SpeechLine line = speechManager.lines[i];<br> if (line.textType == AC_TextType.Speech)<br> {<br> int lineNumUpdated = RenameAudio (speechManager, line, move);<br> numAssigned += lineNumUpdated;<br> }<br> }<br> <br> AssetDatabase.SaveAssets ();<br> <br> EditorUtility.ClearProgressBar ();<br> EditorUtility.DisplayDialog ("Renaming files", "Process complete. " + numAssigned + " lines were updated. The audio files should now be moved into a Resources folder.", "OK");<br> }<br> else<br> {<br> Debug.LogWarning ("No Speech Manager assigned");<br> }<br> }<br> }<br> <br> <br> private static int RenameAudio (SpeechManager speechManager, SpeechLine line, bool move)<br> {<br> int numUpdated = 0;<br> if (RenameAudio (speechManager, line, 0, move))<br> {<br> numUpdated ++;<br> }<br> <br> if (speechManager.languages != null && speechManager.languages.Count > 1 && speechManager.translateAudio)<br> {<br> for (int i=1; i<speechManager.languages.Count; i++)<br> {<br> if (RenameAudio (speechManager, line, i, move))<br> {<br> numUpdated ++;<br> }<br> }<br> }<br> <br> return numUpdated;<br> }<br> <br> <br> private static bool RenameAudio (SpeechManager speechManager, SpeechLine line, int languageIndex, bool move)<br> {<br> AudioClip audioClip = (languageIndex <= 0) ? line.customAudioClip : line.customTranslationAudioClips [languageIndex-1];<br> <br> if (audioClip == null)<br> {<br> return false;<br> }<br> <br> string fullFilenameAndPath = AssetDatabase.GetAssetPath (audioClip);<br> <br> if (string.IsNullOrEmpty (fullFilenameAndPath))<br> {<br> return false;;<br> }<br> <br> int lastSlashIndex = fullFilenameAndPath.LastIndexOf ("/") + 1;<br> int lastDotIndex = fullFilenameAndPath.LastIndexOf (".");<br> <br> if (lastSlashIndex <= 1 || lastDotIndex <= lastSlashIndex)<br> {<br> return false;<br> }<br> <br> string newFilename = line.GetFilename () + line.lineID.ToString ();<br> <br> string error = AssetDatabase.RenameAsset (fullFilenameAndPath, newFilename);<br> <br> if (!string.IsNullOrEmpty (error))<br> {<br> Debug.LogWarning ("Error renaming '" + fullFilenameAndPath + "' - " + error);<br> return false;<br> }<br> <br> if (move)<br> {<br> fullFilenameAndPath = AssetDatabase.GetAssetPath (audioClip);<br> string baseFolder = "Assets/Resources/" + speechManager.autoSpeechFolder;<br> <br> if (speechManager.placeAudioInSubfolders)<br> {<br> if (!AssetDatabase.IsValidFolder (baseFolder + "/" + line.GetFilename ()))<br> {<br> AssetDatabase.CreateFolder (baseFolder, line.GetFilename ());<br> }<br> baseFolder += "/" + line.GetFilename ();<br> }<br> <br> if (languageIndex > 0)<br> {<br> string languageName = speechManager.languages[languageIndex];<br> if (!AssetDatabase.IsValidFolder (baseFolder + "/" + languageName))<br> {<br> AssetDatabase.CreateFolder (baseFolder, languageName);<br> }<br> <br> baseFolder += "/" + languageName;<br> }<br> <br> baseFolder += "/" + newFilename;<br> <br> error = AssetDatabase.MoveAsset (fullFilenameAndPath, baseFolder);<br> <br> if (!string.IsNullOrEmpty (error))<br> {<br> Debug.LogWarning ("Error moving '" + fullFilenameAndPath + "' to '" + baseFolder + "' - " + error);<br> return false;<br> }<br> }<br> <br> if (languageIndex <= 0)<br> {<br> line.customAudioClip = null;<br> }<br> else<br> {<br> line.customTranslationAudioClips[languageIndex-1] = null;<br> }<br> return true;<br> }<br> <br> } [[Category:General]]
Summary:
Please note that all contributions to the Adventure Creator Wikia are considered to be released under the CC-BY-SA
Cancel
Editing help
(opens in new window)
Follow on IG
TikTok
Join Fan Lab