示例#1
0
 private void prepareVoice(DirectoryInfo voiceDirectory)
 {
     Console.WriteLine("Preparing voice messages");
     DirectoryInfo[] eventFolders = voiceDirectory.GetDirectories();
     foreach (DirectoryInfo eventFolder in eventFolders)
     {
         Boolean alwaysKeepCached = this.allowCaching && this.eventTypesToKeepCached.Contains(eventFolder.Name);
         try
         {
             DirectoryInfo[] eventDetailFolders = eventFolder.GetDirectories();
             foreach (DirectoryInfo eventDetailFolder in eventDetailFolders)
             {
                 String   fullEventName = eventFolder.Name + "/" + eventDetailFolder.Name;
                 SoundSet soundSet      = new SoundSet(eventDetailFolder, this.useSwearyMessages, alwaysKeepCached, this.allowCaching);
                 if (soundSet.hasSounds)
                 {
                     availableSounds.Add(fullEventName);
                     soundSets.Add(fullEventName, soundSet);
                     if (alwaysKeepCached)
                     {
                         currentLoadedCount += soundSet.soundsCount;
                     }
                 }
             }
         }
         catch (DirectoryNotFoundException)
         {
             Console.WriteLine("Unable to find events folder");
         }
     }
     Console.WriteLine("Prepare voice message completed");
 }
示例#2
0
        private void preparePrefixesAndSuffixes(DirectoryInfo personalisationsDirectory, String selectedPersonalisation)
        {
            Console.WriteLine("Preparing personalisations for selected name " + selectedPersonalisation);
            DirectoryInfo[] namesFolders = personalisationsDirectory.GetDirectories();
            foreach (DirectoryInfo namesFolder in namesFolders)
            {
                if (namesFolder.Name.Equals(selectedPersonalisation, StringComparison.InvariantCultureIgnoreCase))
                {
                    DirectoryInfo[] prefixesAndSuffixesFolders = namesFolder.GetDirectories();
                    if (prefixesAndSuffixesFolders.Length == 1)
                    {
                        foreach (DirectoryInfo prefixesAndSuffixesFolder in prefixesAndSuffixesFolders[0].GetDirectories())
                        {
                            Boolean alwaysKeepCached = this.allowCaching && this.eventTypesToKeepCached.Contains(prefixesAndSuffixesFolder.Name);

                            SoundSet soundSet = new SoundSet(prefixesAndSuffixesFolder, this.useSwearyMessages, alwaysKeepCached, this.allowCaching);
                            if (soundSet.hasSounds)
                            {
                                availablePrefixesAndSuffixes.Add(prefixesAndSuffixesFolder.Name);
                                soundSets.Add(prefixesAndSuffixesFolder.Name, soundSet);
                                if (alwaysKeepCached)
                                {
                                    currentLoadedCount += soundSet.soundsCount;
                                }
                            }
                        }
                    }
                    break;
                }
            }
            Console.WriteLine("Prepare personalisations completed");
        }
示例#3
0
        private void preparePrefixesAndSuffixes(DirectoryInfo prefixesAndSuffixesDirectory)
        {
            Console.WriteLine("Preparing personalisations");
            DirectoryInfo[] prefixesAndSuffixesFolders = prefixesAndSuffixesDirectory.GetDirectories();
            foreach (DirectoryInfo prefixesAndSuffixesFolder in prefixesAndSuffixesFolders)
            {
                Boolean alwaysKeepCached = this.allowCaching && this.eventTypesToKeepCached.Contains(prefixesAndSuffixesFolder.Name);

                SoundSet soundSet = new SoundSet(prefixesAndSuffixesFolder, this.useSwearyMessages, alwaysKeepCached, this.allowCaching);
                if (soundSet.hasSounds)
                {
                    availablePrefixesAndSuffixes.Add(prefixesAndSuffixesFolder.Name);
                    soundSets.Add(prefixesAndSuffixesFolder.Name, soundSet);
                    if (alwaysKeepCached)
                    {
                        currentLoadedCount += soundSet.soundsCount;
                    }
                }
            }
            Console.WriteLine("Prepare personalisations completed");
        }
示例#4
0
 private void initialise()
 {
     try
     {
         FileInfo[] soundFiles = this.soundFolder.GetFiles();
         foreach (FileInfo soundFile in soundFiles)
         {
             if (soundFile.Name.EndsWith(".wav"))
             {
                 Boolean isSweary = soundFile.Name.Contains("sweary");
                 if (this.useSwearyMessages || !isSweary)
                 {
                     if (soundFile.Name.Contains(SoundCache.REQUIRED_PREFIX_IDENTIFIER) || soundFile.Name.Contains(SoundCache.REQUIRED_SUFFIX_IDENTIFIER) ||
                         soundFile.Name.Contains(SoundCache.OPTIONAL_PREFIX_IDENTIFIER) || soundFile.Name.Contains(SoundCache.OPTIONAL_PREFIX_IDENTIFIER))
                     {
                         Boolean isOptional = soundFile.Name.Contains(SoundCache.OPTIONAL_PREFIX_IDENTIFIER) || soundFile.Name.Contains(SoundCache.OPTIONAL_SUFFIX_IDENTIFIER);
                         foreach (String prefixSuffixName in SoundCache.availablePrefixesAndSuffixes)
                         {
                             if (soundFile.Name.Contains(prefixSuffixName) && SoundCache.soundSets.ContainsKey(prefixSuffixName))
                             {
                                 SoundSet additionalSoundSet = SoundCache.soundSets[prefixSuffixName];
                                 if (additionalSoundSet.hasSounds)
                                 {
                                     hasPrefixOrSuffix = true;
                                     hasSounds         = true;
                                     SingleSound singleSound = new SingleSound(soundFile.FullName, SoundCache.eagerLoadSoundFiles, this.keepCached, this.allowCaching);
                                     singleSound.isSweary = isSweary;
                                     if (soundFile.Name.Contains(SoundCache.OPTIONAL_SUFFIX_IDENTIFIER) || soundFile.Name.Contains(SoundCache.REQUIRED_SUFFIX_IDENTIFIER))
                                     {
                                         singleSound.suffixSoundSet = additionalSoundSet;
                                     }
                                     else
                                     {
                                         singleSound.prefixSoundSet = additionalSoundSet;
                                     }
                                     singleSoundsWithPrefixOrSuffix.Add(singleSound);
                                     SoundCache.prefixesAndSuffixesCount++;
                                     soundsCount++;
                                 }
                                 break;
                             }
                         }
                         if (isOptional)
                         {
                             hasSounds = true;
                             SingleSound singleSound = new SingleSound(soundFile.FullName, SoundCache.eagerLoadSoundFiles, this.keepCached, this.allowCaching);
                             singleSound.isSweary = isSweary;
                             singleSoundsNoPrefixOrSuffix.Add(singleSound);
                             soundsCount++;
                         }
                     }
                     else
                     {
                         hasSounds = true;
                         SingleSound singleSound = new SingleSound(soundFile.FullName, SoundCache.eagerLoadSoundFiles, this.keepCached, this.allowCaching);
                         singleSound.isSweary = isSweary;
                         singleSoundsNoPrefixOrSuffix.Add(singleSound);
                         soundsCount++;
                     }
                 }
             }
         }
     }
     catch (DirectoryNotFoundException)
     {
     }
     initialised = true;
 }
示例#5
0
        public void Play(List <String> soundNames)
        {
            SoundSet           prefix             = null;
            SoundSet           suffix             = null;
            List <SingleSound> singleSoundsToPlay = new List <SingleSound>();

            foreach (String soundName in soundNames)
            {
                if (soundName.StartsWith(AudioPlayer.PAUSE_ID))
                {
                    int pauseLength = 500;
                    try
                    {
                        String[] split = soundName.Split(':');
                        if (split.Count() == 2)
                        {
                            pauseLength = int.Parse(split[1]);
                        }
                    }
                    catch (Exception) { }
                    singleSoundsToPlay.Add(new SingleSound(pauseLength));
                }
                else if (soundName.StartsWith(TTS_IDENTIFIER))
                {
                    singleSoundsToPlay.Add(new SingleSound(soundName.Substring(TTS_IDENTIFIER.Count())));
                }
                else
                {
                    Boolean     preferPersonalised = personalisedMessageIsDue();
                    SingleSound singleSound        = null;
                    if (soundSets.ContainsKey(soundName))
                    {
                        SoundSet soundSet = soundSets[soundName];
                        singleSound = soundSet.getSingleSound(preferPersonalised);
                        if (!soundSet.keepCached)
                        {
                            if (dynamicLoadedSounds.Contains(soundName))
                            {
                                dynamicLoadedSounds.Remove(soundName);
                            }
                            dynamicLoadedSounds.Add(soundName);
                        }
                    }
                    else if (singleSounds.ContainsKey(soundName))
                    {
                        singleSound = singleSounds[soundName];
                    }
                    if (singleSound != null)
                    {
                        // hack... we double check the prefer setting here and only play the prefix / suffix if it's true.
                        // The list without prefixes and suffixes includes items which have optional ones, so we might want to
                        // play a sound that can have the prefix / suffix, but not the associated prefix / suffix
                        if (preferPersonalised && singleSound.prefixSoundSet != null)
                        {
                            prefix = singleSound.prefixSoundSet;
                        }
                        if (preferPersonalised && singleSound.suffixSoundSet != null)
                        {
                            suffix = singleSound.suffixSoundSet;
                        }
                        singleSoundsToPlay.Add(singleSound);
                    }
                }
            }
            if (singleSounds.Count > 0)
            {
                if (prefix != null)
                {
                    singleSoundsToPlay.Insert(0, prefix.getSingleSound(false));
                    lastPersonalisedMessageTime = DateTime.Now;
                }
                if (suffix != null)
                {
                    singleSoundsToPlay.Add(suffix.getSingleSound(false));
                    lastPersonalisedMessageTime = DateTime.Now;
                }
                foreach (SingleSound singleSound in singleSoundsToPlay)
                {
                    if (singleSound.isPause)
                    {
                        Thread.Sleep(singleSound.pauseLength);
                    }
                    else
                    {
                        if (singleSound.Play())
                        {
                            currentLoadedCount++;
                        }
                    }
                }
            }
        }