Skip to content
Snippets Groups Projects
Commit 531e3efc authored by AevaMorigi's avatar AevaMorigi
Browse files

fixed previousVoice [wip][dnm]

ToDo: remove all the debug messages
parent 0e2dc102
No related branches found
No related tags found
No related merge requests found
......@@ -455,15 +455,31 @@ namespace TeachR.StructureTree
}
StudentController sc = studentSlot.GetComponent<StudentController>();
string pathOfAudioFile = StructureTreeHandler.GetPathOfAudioFile(StructureTreeHandler.stc[currentNode],
sc.IsMale, sc.StudentObj.PreviousVoice);
Debug.Log($"StartTalkPerformedBy: {studentSlot.name}");
string soundFileFolder = StructureTreeHandler.stc[currentNode].soundFileName;
string previousVoice = sc.StudentObj.PreviousVoice;
string pathOfAudioFile = StructureTreeHandler.GetPathOfAudioFile(soundFileFolder, sc.IsMale, previousVoice);
if (pathOfAudioFile != "")
{
string audioFileName = Path.GetFileNameWithoutExtension(pathOfAudioFile);
if (audioFileName.Contains("_"))
Debug.Log($"audioFileName: {audioFileName}");
if (string.IsNullOrEmpty(previousVoice)) // set previous voice if not set before
{
string voice = audioFileName.Replace(soundFileFolder, "").Replace("_", "").Replace("-", "");
Debug.Log($"previousVoice: {voice}");
if (!string.IsNullOrEmpty(voice))
{
sc.StudentObj.PreviousVoice = voice;
Debug.Log($"set previousVoice to {voice}");
}
else
Debug.Log($"previousVoice was set to {voice} before");
}
else if (!audioFileName.Contains(previousVoice))
{
string voice = audioFileName.Split("_")[^1];
sc.StudentObj.PreviousVoice = voice;
Debug.Log($"Attention! previousVoice {previousVoice} not found in folder {soundFileFolder}");
}
//first time find UnityWaiter
......@@ -490,6 +506,8 @@ namespace TeachR.StructureTree
bc.HeadIK.TurnTo(AllStudentAttributes.Teacher.transform);
bc.PlayImpulse();
}
else
Debug.Log($"no path for audioFile set {pathOfAudioFile}, currentNode: {currentNode}, student: {studentSlot.name}");
if (StructureTreeHandler.classHasGlobalKnowledge)
{
......
......@@ -37,36 +37,33 @@ namespace TeachR.StructureTree
// Look for the soundFile, which is referenced by the structureTree.
// Look for genderspecific sounds.
// Take one fitting at random.
public static string GetPathOfAudioFile(GraphToTreeConverter.StructureTreeNode stn, bool isMaleVoice, string previousVoice)
public static string GetPathOfAudioFile(string soundFileName, bool isMaleVoice, string previousVoice)
{
if (stn.soundFileName == null || stn.soundFileName == "KM" || stn.soundFileName == "")
{
return "";
}
if (string.IsNullOrEmpty(soundFileName) || soundFileName == "KM") return "";
string path = Application.streamingAssetsPath +
"/Config~/" + themeFolder +
"/Audioaufnahmen/" + stn.soundFileName;
if (isMaleVoice)
{
path = path + "m";
}
else
{
path = path + "w";
}
path = path + "/";
// For more variety, there should be several voice files for each answer. Choose one at random:
"/Audioaufnahmen/" + soundFileName;
path += (isMaleVoice ? "m" : "w") + "/"; // path of folder
// For more variety, there should be several voice files for each answer. Choose one at random:
string[] audioFileNames = Directory.GetFiles(path);
Debug.Log($"path: {path}, previousVoice: {previousVoice}");
Assert.IsTrue(audioFileNames.Length > 0);
if (previousVoice != "") // Choose a file using the same voice as previousVoice
if (audioFileNames.Length == 0)
Debug.LogError($"No audiofiles found in folder {path}");
else
{
string[] voiceAudioFileNames = audioFileNames.Where(
filePath => Path.GetFileNameWithoutExtension(filePath).Contains(previousVoice)
).ToArray();
audioFileNames = voiceAudioFileNames.Length > 0 ? voiceAudioFileNames : audioFileNames;
if (!string.IsNullOrEmpty(previousVoice)) // previous voice was chosen
{
string[] voiceAudioFileNames = audioFileNames.Where(
filePath => Path.GetFileNameWithoutExtension(filePath).Contains(previousVoice)).ToArray();
audioFileNames = voiceAudioFileNames.Length > 0 ? voiceAudioFileNames : audioFileNames;
Debug.Log($"Found {voiceAudioFileNames.Length} audiofiles for previousVoice {previousVoice}");
}
else // no previous voice was chosen
{
Debug.Log("no previousVoice set");
}
}
path = audioFileNames[Random.Range(0, audioFileNames.Length - 1)];
......
......@@ -10,7 +10,24 @@ namespace TeachR.Student
public bool IsTall;
public string ModelName;
public bool IsLeftHanded;
public string PreviousVoice;
//public string PreviousVoice;
public StudentBehaviourObject behaviour;
// temporary change for debug:
[SerializeField] private string previousVoice;
public string PreviousVoice
{
get => previousVoice;
set
{
if (previousVoice != value)
{
Debug.Log($"PreviousVoice changed from {previousVoice} to {value}");
previousVoice = value;
}
else
Debug.Log($"PreviousVoice stayed at {previousVoice}");
}
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment