//public static void PostProcessSound() //{ } public static bool ShouldPlaySound(SingleSound singleSound, SoundMetadata soundMetadata) { if (PlaybackModerator.crewChief != null && !PlaybackModerator.crewChief.running) { PlaybackModerator.Trace(string.Format("Sound {0} rejected because main thread is shutting down", singleSound.fullPath)); return(false); } int messageId = soundMetadata == null ? 0 : soundMetadata.messageId; if (PlaybackModerator.lastBlockedMessageId == messageId) { PlaybackModerator.Trace(string.Format("Sound {0} rejected because other members of the same message have been blocked", singleSound.fullPath)); return(false); } if (PlaybackModerator.rejectMessagesWhenTalking && soundMetadata.type != SoundType.VOICE_COMMAND_RESPONSE && SpeechRecogniser.waitingForSpeech && MainWindow.voiceOption != MainWindow.VoiceOptionEnum.ALWAYS_ON) { PlaybackModerator.Trace(string.Format("Sound {0} rejected because we're in the middle of a voice command", singleSound.fullPath)); if (messageId != 0) { PlaybackModerator.lastBlockedMessageId = messageId; } return(false); } if (PlaybackModerator.minPriorityForInterrupt != SoundType.OTHER && PlaybackModerator.CanInterrupt(soundMetadata)) { SoundType mostImportantTypeInImmediateQueue = PlaybackModerator.audioPlayer.getPriortyOfFirstWaitingImmediateMessage(); if (mostImportantTypeInImmediateQueue <= PlaybackModerator.minPriorityForInterrupt) { PlaybackModerator.Trace(string.Format("Blocking queued messasge {0} because at least 1 {1} message is waiting", singleSound.fullPath, mostImportantTypeInImmediateQueue)); PlaybackModerator.Trace("Messages triggering block logic: " + audioPlayer.getMessagesBlocking(minPriorityForInterrupt)); if (messageId != 0) { PlaybackModerator.lastBlockedMessageId = messageId; } // ensure the blocking message won't expire var firstWaitingMessage = PlaybackModerator.audioPlayer.getFirstWaitingImmediateMessage(mostImportantTypeInImmediateQueue); if (firstWaitingMessage != null && firstWaitingMessage.expiryTime > 0) { firstWaitingMessage.expiryTime = firstWaitingMessage.expiryTime + 2000; } return(false); } } return(true); }
public static void PreProcessSound(SingleSound sound, SoundMetadata soundMetadata) { if (PlaybackModerator.audioPlayer == null) { return; } //PlaybackModerator.Trace($"Pre-Processing sound: {sound.fullPath} isSpotter: {sound.isSpotter} isBleep: {sound.isBleep} "); PlaybackModerator.InjectBeepOutIn(sound, soundMetadata); PlaybackModerator.lastSoundPreProcessed = sound; }
public SingleSound getSingleSound(Boolean preferPersonalised) { if (!initialised) { initialise(); } if (preferPersonalised && singleSoundsWithPrefixOrSuffix.Count > 0) { if (prefixOrSuffixIndexes == null || prefixOrSuffixIndexesPosition == prefixOrSuffixIndexes.Count) { prefixOrSuffixIndexes = createIndexes(singleSoundsWithPrefixOrSuffix.Count()); prefixOrSuffixIndexesPosition = 0; } SingleSound ss = null; while (prefixOrSuffixIndexesPosition < prefixOrSuffixIndexes.Count()) { ss = singleSoundsWithPrefixOrSuffix[prefixOrSuffixIndexes[prefixOrSuffixIndexesPosition]]; prefixOrSuffixIndexesPosition++; if (!ss.isSweary) { break; } else { // this is a sweary message - can we play it? do we have to play it? if (prefixOrSuffixIndexesPosition == prefixOrSuffixIndexes.Count || DateTime.Now > SoundCache.lastSwearyMessageTime + TimeSpan.FromSeconds(10)) { SoundCache.lastSwearyMessageTime = DateTime.Now; break; } } } return(ss); } else if (singleSoundsNoPrefixOrSuffix.Count > 0) { if (indexes == null || indexesPosition == indexes.Count) { indexes = createIndexes(singleSoundsNoPrefixOrSuffix.Count()); indexesPosition = 0; } SingleSound ss = null; while (indexesPosition < indexes.Count()) { ss = singleSoundsNoPrefixOrSuffix[indexes[indexesPosition]]; indexesPosition++; if (!ss.isSweary) { break; } else { // this is a sweary message - can we play it? do we have to play it? if (indexesPosition == indexes.Count || DateTime.Now > SoundCache.lastSwearyMessageTime + TimeSpan.FromSeconds(10)) { SoundCache.lastSwearyMessageTime = DateTime.Now; break; } } } return(ss); } else { return(null); } }
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; }
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++; } } } } }
private static void InjectBeepOutIn(SingleSound sound, SoundMetadata soundMetadata) { Debug.Assert(PlaybackModerator.audioPlayer != null, "audioPlayer is not set."); // Only consider injection is preference is set and Spotter and Chief are different personas. if (!PlaybackModerator.IsFakeBleepInjectionEnabled()) { return; } // Skip bleep sounds. if (sound.isBleep) { return; } // Inject bleep out/in if needed. var isSpotterSound = sound.isSpotter; // Alternatively, we could assign a role to each queued sound. We'll need this if we get more "personas" than Chief and Spotter. if (((!PlaybackModerator.lastSoundWasSpotter && isSpotterSound) || // If we are flipping from the Chief to Spotter (PlaybackModerator.lastSoundWasSpotter && !isSpotterSound)) && // Or from the Spotter to Chief PlaybackModerator.audioPlayer.isChannelOpen() && // And, channel is still open (PlaybackModerator.lastSoundPreProcessed == null || !PlaybackModerator.lastSoundPreProcessed.isBleep)) // and the last sound wasn't also a beep (to stop the spotter kicking off with a double-beep) { // Ok, so idea here is that Chief and Spotter have different bleeps. So we use opposing sets. string keyBleepOut = null; string keyBleepIn = null; string traceMsgPostfix = null; if (isSpotterSound) { // Spotter uses opposite blips. keyBleepOut = "end_bleep"; // Chief uses regular bleeps. keyBleepIn = "alternate_short_start_bleep"; traceMsgPostfix = "Spotter interrupted Chief."; } else // Chief comes in. { keyBleepOut = "alternate_end_bleep"; // Spotter uses alternate bleeps keyBleepIn = "short_start_bleep"; traceMsgPostfix = "Chief interrupted Spotter."; } PlaybackModerator.Trace(string.Format("Injecting: {0} and {1} messages. {2}", keyBleepOut, keyBleepIn, traceMsgPostfix)); // insert bleep out/in if (PlaybackModerator.insertBeepOutBetweenSpotterAndChief) { PlaybackModerator.audioPlayer.getSoundCache().Play(keyBleepOut, soundMetadata); } // would be nice to have some slight random silence here if (PlaybackModerator.insertBeepInBetweenSpotterAndChief) { PlaybackModerator.audioPlayer.getSoundCache().Play(keyBleepIn, soundMetadata); } } PlaybackModerator.lastSoundWasSpotter = isSpotterSound; }