fix the code below the logic in reverb and fade is causing things to play twice. private…
- User
fix the code below the logic in reverb and fade is causing things to play twice.
private void PlayAudio(InputSimulator ISim, TimeSpan duration) { lock (_lock) { if (ChatCombo) { // Create an instance of InputSimulator var simulator = new InputSimulator();
// Simulate pressing the Enter key simulator.Keyboard.KeyPress(VirtualKeyCode.RETURN);
// Wait for a short duration to ensure the Enter key action is completed Thread.Sleep(40); // Adjust the delay as necessary
// Simulate pressing Control + V to paste simulator.Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_V);
Thread.Sleep(30); // Adjust the delay as necessary
// Simulate pressing the Enter key simulator.Keyboard.KeyPress(VirtualKeyCode.RETURN); }
// Dispose of the previous audio file reader and wave out if they exist _audioFileReader?.Dispose(); _waveOut?.Stop(); _waveOut?.Dispose();
// Create a new WaveOutEvent and AudioFileReader _waveOut = new WaveOutEvent(); if (Reverb == true && Fade == false) { AddFX(true, false);
Thread.Sleep(500);
_audioFileReader = new AudioFileReader(Path.Combine(_directoryPath, "Reverb.wav"));
// Set the WaveOut to play the audio file _waveOut.Init(_audioFileReader);
// Play the audio file _waveOut.Play(); } else if (Fade == true && Reverb == false) { AddFX(false, true);
Thread.Sleep(500);
_audioFileReader = new AudioFileReader(Path.Combine(_directoryPath, "Fade.wav"));
// Set the WaveOut to play the audio file _waveOut.Init(_audioFileReader);
// Play the audio file _waveOut.Play(); } else if(Fade == true && Reverb == true) { AddFX(true, true);
Thread.Sleep(1000);
_audioFileReader = new AudioFileReader(Path.Combine(_directoryPath, "FadeVerb.wav"));
// Set the WaveOut to play the audio file _waveOut.Init(_audioFileReader);
// Play the audio file _waveOut.Play(); } else if(Fade == false && Reverb == false) { _audioFileReader = new AudioFileReader(Path.Combine(_directoryPath, "audio.wav"));
// Set the WaveOut to play the audio file _waveOut.Init(_audioFileReader);
// Play the audio file _waveOut.Play(); } // Press and hold the '4' key ISim.Keyboard.KeyDown(VirtualKeyCode.VK_9);
// Wait for the duration of the wave file Thread.Sleep((int)duration.TotalMilliseconds + 1000);
// Release the '4' key ISim.Keyboard.KeyUp(VirtualKeyCode.VK_9);
// Wait for the audio to finish playing Task.Run(() => { while (_waveOut.PlaybackState == PlaybackState.Playing) { Task.Delay(100).Wait(); }
// Clean up after playback is complete _audioFileReader.Dispose(); _waveOut.Dispose(); }); } }
- Assistant
- User
optimize the script
void AddFX(bool Reverb, bool Fade) { List Lines = new List();
- Assistant