Skip to content

Commit

Permalink
Created Sentence value type
Browse files Browse the repository at this point in the history
+ fixed compilation bug where attendancemanager usage was not fully updated for its previous refactor.
+ removed unecessary argument from Pronunciation.GetLettersPronunciation()
  • Loading branch information
Samuel committed Mar 14, 2018
1 parent 29e8b6c commit 8cc7c38
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 20 deletions.
4 changes: 3 additions & 1 deletion ChatEntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using System;
using SETextToSpeechMod.LookUpTables;
using SETextToSpeechMod.Processing;

namespace SETextToSpeechMod
{
Expand Down Expand Up @@ -138,6 +139,7 @@ public void OnReceivedPacket (byte[] receivedPacket) //action type method which
{
string decoded = encode.GetString (receivedPacket);
string signature = ExtractSignatureFromPacket (ref decoded);
Sentence inputSentence = new Sentence(decoded);

if (decoded.Length > OutputManager.MAX_LETTERS && //letter limit for mental health concerns.
debugging == false)
Expand All @@ -147,7 +149,7 @@ public void OnReceivedPacket (byte[] receivedPacket) //action type method which

else
{
OutputManager.CreateNewSpeech (signature, decoded);
OutputManager.CreateNewSpeech (signature, inputSentence);
}
}

Expand Down
11 changes: 6 additions & 5 deletions Output/OutputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace SETextToSpeechMod
{
public class OutputManager : ISentenceReset
public class OutputManager
{
public const int MAX_LETTERS = 100;
const int UPDATES_INTERVAL = 60;
Expand Down Expand Up @@ -38,7 +38,8 @@ public List <SpeechTask> Speeches

private readonly List <SpeechTask> speechesFields = new List <SpeechTask>();
private SoundPlayer soundPlayerRef;
TaskFactory taskFactory = new TaskFactory();
TaskFactory taskFactory = new TaskFactory();
private AttendanceManager attendanceManager = AttendanceManager.GetSingleton();

public static bool IsDebugging { get; private set;}
public bool IsProcessingOutputs { get; private set;}
Expand All @@ -57,7 +58,7 @@ public OutputManager (SoundPlayer inputEmitter, bool isDebugging)
FactoryReset();
}

public void FactoryReset(params string[] toProcess)
private void FactoryReset()
{
IsProcessingOutputs = false;
typeIndexes = new int[PossibleOutputs.Collection.Count];
Expand Down Expand Up @@ -114,7 +115,7 @@ public void Run()
if (timer <= 0) //a little timer will prevent the emitter from oscillating between your eyes.
{
timer = UPDATES_INTERVAL;
soundPlayerRef.UpdatePosition (AttendanceManager.LocalPlayer);
soundPlayerRef.UpdatePosition (attendanceManager.LocalPlayer);
}

else
Expand Down Expand Up @@ -152,7 +153,7 @@ private int GetOutputTypesIndex (string scrutinizedTypeName)
/// </summary>
/// <param name="validVoiceType"></param>
/// <param name="sentence"></param>
public bool CreateNewSpeech (string validVoiceTypeName, string inputSentence)
public bool CreateNewSpeech (string validVoiceTypeName, Sentence inputSentence)
{
bool outcome = default (bool);

Expand Down
5 changes: 3 additions & 2 deletions Output/SpeechTask.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using SETextToSpeechMod.Processing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -35,7 +36,7 @@ public async Task RunAsync()
await ReturnInfo;
}

public void FactoryReset (string inputSentence)
public void FactoryReset (Sentence inputSentence)
{
TaskCanceller.Cancel();
RenewCancellationSource();
Expand Down
2 changes: 1 addition & 1 deletion Processing/ISentenceReset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ namespace SETextToSpeechMod.Processing
{
interface ISentenceReset
{
void FactoryReset(string newSentence);
void FactoryReset(Sentence newSentence);
}
}
13 changes: 7 additions & 6 deletions Processing/Pronunciation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public class Pronunciation : ISentenceReset
string surroundingPhrase;
List <string> currentResults = new List <string>(); //re used a lot so dont put dictonary and adjacent results in at the same time!
bool pushingDictionaryWordOut;
string tempSentence; //temps should remain conventionally readonly for each separate letter analysis.
readonly int sentenceLength;

Sentence tempSentence; //temps should remain conventionally readonly for each separate letter analysis.
int tempLetterIndex;

public Pronunciation (Intonation intonationType)
Expand All @@ -37,7 +39,7 @@ public Pronunciation (Intonation intonationType)
this.intonationGen = intonationType;
}

public void FactoryReset(string newSentence)
public void FactoryReset(Sentence newSentence)
{
surroundingPhrase = string.Empty;
PreviousProcessUsedDictionary = false;
Expand All @@ -46,7 +48,7 @@ public void FactoryReset(string newSentence)
currentResults.Clear();
dictionaryMatch = null;

tempSentence = string.Empty;
tempSentence = newSentence;
tempLetterIndex = 0;

pushingDictionaryWordOut = false;
Expand All @@ -61,12 +63,11 @@ public void FactoryReset(string newSentence)
/// <param name="sentence"></param>
/// <param name="letterIndex"></param>
/// <returns>returns new list.</returns>
public List <string> GetLettersPronunciation (string sentence, int letterIndex)
public List <string> GetLettersPronunciation (int letterIndex)
{
pushingDictionaryWordOut = false;
currentResults = new List <string>();
WordIsolator.MoveNext(); //Incrementing the WordIsolator must happen at the beginning of a new letter analysis. This is so optional debugger can pick up accurate properties after each letter analysis.
tempSentence = sentence;
tempLetterIndex = letterIndex;
currentResults.Clear();
surroundingPhrase = string.Empty;
Expand Down Expand Up @@ -108,7 +109,7 @@ public void FactoryReset(string newSentence)

if (OutputManager.IsDebugging == false) //debugger only checks that the correct phonemes were selected; doesnt care about intonation
{
bool sentenceIsEnding = (letterIndex >= sentence.Length - SENTENCE_END_ZONES_LENGTH) ? true : false;
bool sentenceIsEnding = (letterIndex >= tempSentence.Length - SENTENCE_END_ZONES_LENGTH) ? true : false;

for (int i = default (int); i < currentResults.Count; i++)
{
Expand Down
29 changes: 29 additions & 0 deletions Processing/Sentence.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SETextToSpeechMod.Processing
{
public struct Sentence
{
public char this[int index]
{
get => sentenceValue[index];
}
private string sentenceValue;

public int Length => sentenceValue.Length;

public Sentence (string sentenceValue)
{
this.sentenceValue = sentenceValue;
}

public override string ToString()
{
return sentenceValue;
}
}
}
6 changes: 3 additions & 3 deletions Processing/TimelineFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public abstract class TimelineFactory : ISentenceReset
public DebugOutputContainer PossibleDebugOutput {get; private set;}

//loading data
protected string sentence = string.Empty;
protected Sentence sentence;
bool previousWasSpace;
int syllableMeasure;
protected int[] intonationArrayChosen;
Expand Down Expand Up @@ -56,7 +56,7 @@ public TimelineFactory (SoundPlayer inputEmitter, Intonation intonationType)
/// Initialises a new sentence.
/// </summary>
/// <param name="inputSentence"></param>
public void FactoryReset (string inputSentence)
public void FactoryReset (Sentence inputSentence)
{
IsBusy = false;
HasAnOrder = true;
Expand Down Expand Up @@ -96,7 +96,7 @@ await Task.Run (() => {

private void AddPhonemes (int currentIndex)
{
currentResults = Pronunciation.GetLettersPronunciation (sentence, currentIndex);
currentResults = Pronunciation.GetLettersPronunciation (currentIndex);

for (int i = 0; i < currentResults.Count; i++)
{
Expand Down
4 changes: 2 additions & 2 deletions Processing/WordIsolator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ public int WordsIndexLimit
public string Current => currentWord;
object IEnumerator.Current => currentWord;

string tempSentence;
Sentence tempSentence;
int tempLetterIndex;
private string currentWord;

public void FactoryReset(string newSentence)
public void FactoryReset(Sentence newSentence)
{
currentWord = EMPTY;
CurrentWordIsNew = false;
Expand Down
1 change: 1 addition & 0 deletions SE TextToSpeechMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@
<Compile Include="Processing\Intonation.cs" />
<Compile Include="Processing\Pronunciation.cs" />
<Compile Include="Processing\ISentenceReset.cs" />
<Compile Include="Processing\Sentence.cs" />
<Compile Include="Processing\TimelineClip.cs" />
<Compile Include="Processing\UnconventionalPhraseException.cs" />
<Compile Include="VoiceCode\GladosVoice\GladosIntonation.cs" />
Expand Down

0 comments on commit 8cc7c38

Please sign in to comment.