/// Play the audio and also get reference to the Player that execute the command public AudioPlayer PlayAndGetThePlayer(AudioCommand command) { // sure the ready player we got here is exactly the player will be assigned to play Command in Play() func var readyPlayer = GetReadyPlayer(); Play(command); return(readyPlayer); }
// Update is called once per frame void Update() { while (AudioCommandQueue.Count > 0) { AudioCommand ac = sounds[AudioCommandQueue.Dequeue()] as AudioCommand; ac.Play(); } }
public bool IsPlayingCommand(AudioCommand command) { if (_command == null) { return(false); } else { return(IsWorking() && _command == command); } }
public bool IsReachLimitInstanceForCommand(AudioCommand cmd) { // no limit if (cmd.limitCfg.maxInstancePertime == 0) { return(false); } // has limit instance var currentPlayerForCmd = GetNumberOfPlayerArePlayingCommand(cmd); return(currentPlayerForCmd >= cmd.limitCfg.maxInstancePertime); }
int GetNumberOfPlayerArePlayingCommand(AudioCommand command) { var sum = 0; for (int i = 0, amount = _players.Count; i < amount; i++) { if (_players[i].IsPlayingCommand(command)) { sum++; } } return(sum); }
int GetNumberOfPlayerArePlayingCommandInTheDefineTime(AudioCommand command, float defineTime) { var sum = 0; for (int i = 0, amount = _players.Count; i < amount; i++) { var player = _players[i]; if (player.IsPlayingCommand(command) && player.IsSamePlayTime(defineTime)) { sum++; } } return(sum); }
public void Play(AudioCommand command) { if (command == null) { return; } // save to current _command = command; _playTime = Time.time; // config AudioSource. Reset all setting first ResetAudioSource(); _source.outputAudioMixerGroup = command.basicCfg.mixerGroup; _clipType = command.basicCfg.clipType; _source.clip = command.GetClipForPlay(); // start the playing process StartPlayingProcess(command); }
public void ProcessRequest(Request req) { if (AUTH != "testAuth") { AlexaCompSERVER.StopServer(); } else { Clog("IS Test Request"); } switch (req.COMMAND) { case "LAUNCH": Launch unused = new Launch(req.PRIMARY); break; case "COMPUTERCOMMAND": SystemCommand unused2 = new SystemCommand(req.PRIMARY); break; case "GETCOMPSTAT": CompStat unused3 = new CompStat(req.PRIMARY, req.SECONDARY, req.TERTIARY); break; case "AUDIOCOMMAND": AudioCommand unused4 = new AudioCommand(req.PRIMARY, req.SECONDARY); break; case "RGBCOMMAND": RGBCommand unused5 = new RGBCommand(req.PRIMARY, req.COLOR1, req.COLOR2); break; case "OPENDEVTOOLS": OpenDevTools unused6 = new OpenDevTools(); break; } req.LogTimeElapsed(); }
static void Main(string[] args) { botClient = new TelegramBotClient("760620360:AAGq9KIBMccVIGo0Rbggq3Hn88ehgLVNq38"); var me = botClient.GetMeAsync().Result; _stickerCommand = new StickerCommand(botClient); _textCommand = new TextCommand(botClient); _videoCommand = new VideoCommand(botClient); _pictureCommand = new PictureCommand(botClient); _rebootCommand = new RebootCommand(botClient); _audioCommand = new AudioCommand(botClient); botClient.OnMessage += BotOnMessage; botClient.StartReceiving(); Console.WriteLine($"Hello World I'm the: ID:{me.Id} / FirstName:{me.FirstName} / Username:{me.Username}!"); Console.WriteLine("Press any key to continue.."); Console.ReadKey(); Console.Clear(); Console.WriteLine("Bye.."); System.Threading.Thread.Sleep(1000); }
public string ProcessCommand(AudioCommand command, string argument1 = "", string argument2 = "") { if (muted && command != AudioCommand.Mute) { return("Muted"); } switch (command) { case AudioCommand.Stop: { return(Stop()); } case AudioCommand.Mute: { return(ToggleMute()); } case AudioCommand.WhiteNoise: { if (busy) { return($"Busy {MainForm.StatusText}"); } return(WhiteNoise()); } case AudioCommand.PinkNoise: { if (busy) { return($"Busy {MainForm.StatusText}"); } return(PinkNoise()); } case AudioCommand.PlayAudio: { if (busy) { return($"Busy {MainForm.StatusText}"); } return(PlayAudio(argument1, argument2)); } case AudioCommand.PlayVoice: { if (busy) { return($"Busy {MainForm.StatusText}"); } return(PlayPlayback(argument1, argument2)); } case AudioCommand.PlayLiveVoice: { if (busy) { return($"Busy {MainForm.StatusText}"); } return(PlayLiveVoice(argument1)); } case AudioCommand.SetVolume: { return(SetVolume(argument1)); } case AudioCommand.SetAudioMode: { if (busy) { return($"Busy {MainForm.StatusText}"); } return(SetAudioMode(argument1)); } case AudioCommand.TTS: { if (busy) { return($"Busy {MainForm.StatusText}"); } return(PlayTTS(argument1)); } default: break; } return("something"); }
/// Execute the input AudioCommand public void Play(AudioCommand cmd) { if (cmd == null) { Log.Warning(false, "Play null SourceAudio, no sound will be played !!!"); return; } // --------- Checking setting // checking max Instance if (cmd.limitCfg.maxInstancePertime > 0) { var currentPlayerForCmd = GetNumberOfPlayerArePlayingCommand(cmd); if (currentPlayerForCmd >= cmd.limitCfg.maxInstancePertime) { if (logWarnings) { Log.Info(cmd, "Audio, reach instance [{0}] for this [{1}], wont play this time", currentPlayerForCmd, cmd.name); } return; } } // check limit frame player if (cmd.limitPerFrameCfg.active) { var currentPlayerForCmd = GetNumberOfPlayerArePlayingCommandInTheDefineTime(cmd, Time.time); if (currentPlayerForCmd >= cmd.limitPerFrameCfg.maxInstance) { if (logWarnings) { Log.Info(cmd, "Audio, reach frame limit [{0}] for this [{1}], wont play this time", currentPlayerForCmd, cmd.name); } return; } } // stop other source if (cmd.stopOtherCfg.active) { for (int n = 0, amount = _players.Count; n < amount; n++) { _players[n].StopIfPlayAnyOfCommands(cmd.stopOtherCfg.others, cmd.stopOtherCfg.fadeOutDuration); } } // fadeOut BGM if (cmd.stopBgmCfg.active) { for (int n = 0, amount = _players.Count; n < amount; n++) { _players[n].StopIfPlayingType(AudioClipType.BGM, cmd.stopBgmCfg.fadeOutDuration); } } // stop all if (cmd.stopAllCfg.active) { for (int n = 0, amount = _players.Count; n < amount; n++) { _players[n].Stop(cmd.stopAllCfg.fadeOutDuration); } } //------------ Play if (cmd.basicCfg.activePlayAudio) { var readyPlayer = GetReadyPlayer(); readyPlayer.Play(cmd); if (logAudioNameOnPlay) { Log.Info(cmd, "Audio [{0}], time {1}, player[{2}]", cmd.name, Time.time, readyPlayer.name); } } //----- Mute if (cmd.muteCfg.active) { ActiveVolumeAll(!cmd.muteCfg.muteAll); } }
public override void LoadView(bool loadData) { AudioCommand.GetDevices(); }
private static int Main(string[] arguments) { // Configure logging. var loggingLevelSwitch = new LoggingLevelSwitch { MinimumLevel = LogEventLevel.Information }; Log.Logger = new LoggerConfiguration() .MinimumLevel.ControlledBy(loggingLevelSwitch) .WriteTo.Console() .CreateLogger(); var showHelp = false; var argumentParser = new ArgumentParser(); argumentParser.Add("help|version|?", "Show this message.", (value) => { showHelp = true; }); argumentParser.Add("verbose|v", "Increase amount of log messages.", (value) => loggingLevelSwitch.MinimumLevel = LogEventLevel.Debug); // Handle all exceptions by showing them in the console try { var commandArgument = arguments.Length > 0 ? arguments[0] : "help"; BaseCommand?command = null; switch (commandArgument) { case "extract": command = new ExtractCommand(argumentParser); break; case "info": command = new InfoCommand(argumentParser); break; case "audio": command = new AudioCommand(argumentParser); break; case "items": command = new ItemsCommand(argumentParser); break; case "help": case "--help": case "--version": commandArgument = "help"; break; } if (command == null) { Program.ShowHelp(argumentParser, commandArgument); return(commandArgument == "help" ? Program.ExitCodeOk : Program.ExitCodeInvalidArgument); } command.Configure(arguments.Skip(1)); // Show help, now with configured argument parser for command-specific help. if (showHelp) { Program.ShowHelp(argumentParser, commandArgument); return(Program.ExitCodeOk); } if (argumentParser.UnparsedArguments.Any()) { // Do not accept invalid arguments because they usually indicate faulty usage foreach (var unparsedArgument in argumentParser.UnparsedArguments) { Console.WriteLine($"Unknown argument \"{unparsedArgument}\"."); } Console.WriteLine(); Program.ShowHelp(argumentParser, commandArgument); return(Program.ExitCodeInvalidArgument); } var exitCode = command.Run(); if (exitCode == Program.ExitCodeInvalidArgument) { Console.WriteLine(); Program.ShowHelp(argumentParser, commandArgument); } return(exitCode); } catch (System.Exception exception) { // Use first exception in aggregates for easier debugging. while (exception is AggregateException && exception.InnerException != null) { exception = exception.InnerException; } // Rethrow for debugger to process. if (Debugger.IsAttached) { throw; } Log.Fatal(exception.Message + "\n" + exception.StackTrace); return(Program.ExitCodeError); } }
IEnumerator IE_PlayingProcess(AudioCommand cmd) { var ticker = new TickHelper(); // check delay first if (cmd.startCfg.delay > 0) { ticker.Reset(cmd.startCfg.delay); yield return(null); while (ticker.Tick()) { yield return(null); } } // play here _source.Play(); // the fadeIn effect if (cmd.startCfg.fadeInDuration > 0) { // first volumne _source.volume = 0f; // fadein ticker.Reset(cmd.startCfg.fadeInDuration); yield return(null); //NOTES : must have this, if not, some short audio maybe stop before it play while (ticker.Tick()) { _source.volume = ticker.GetWaitedTimeInPercent(); yield return(null); } // final volumn _source.volume = 1f; } // check loop if (cmd.loopCfg.active) { _source.loop = cmd.loopCfg.active; if (cmd.loopCfg.limitLoopCount > 0) { var playTime = _source.clip.length * cmd.loopCfg.limitLoopCount; ticker.Reset(playTime); yield return(null); //NOTES : must have this, if not, some short audio maybe stop before it play while (ticker.Tick()) { yield return(null); } // stop after finish waiting Stop(); } } // not loop, then wait for finised sound, then call Stop, also let is "ready" else { // if clip shorter than this, the player maybe stop before the sound start. const float TOO_SHORT_THRESHOLD = 0.08f; ticker.Reset((_source.clip.length < TOO_SHORT_THRESHOLD) ? TOO_SHORT_THRESHOLD : _source.clip.length); yield return(null); //NOTES : must have this, if not, some short audio maybe stop before it play while (ticker.Tick()) { yield return(null); } Stop(); } }
void StartPlayingProcess(AudioCommand cmd) { _playProcess = Observable.FromMicroCoroutine(_ => IE_PlayingProcess(cmd)).Subscribe().AddTo(_destroyDispose); }