Solving the problem of sound in one ear for some videos on Youtube

    Not very long ago I ran into the following problem: when watching some videos on youtube, the sound goes only to the left speaker. When listening through headphones, this causes some inconvenience.

    A software solution was found for Windows 7 using powershell and the NAudio sound library . The main idea is to convert stereo to mono.


    1. Download and unzip the archive with the library
    2. Launch PowerShell ISE Startup from the Menu
    3. Connect types from the library, replacing the path with your own:
      add-type -path 'C:/Users/xxxxx/Downloads/NAudio-Release/NAudio.dll'
      
    4. Remember id of default audio output device:
      $devices = new-object NAudio.CoreAudioApi.MMDeviceEnumerator
      $defaultDevice = $devices.GetDefaultAudioEndpoint([NAudio.CoreAudioApi.DataFlow]::Render, [NAudio.CoreAudioApi.Role]::Multimedia)
      $defaultDeviceId = $defaultDevice.ID -replace '{.+}\.{(.+)}$', '$1'
      
    5. Change the default sound output device to any alternative (programs should not be able to change it):
      Control Panel-> Hardware and Sound-> Sound-> Playback
    6. Run the following code, after replacing the device id with your own:
      $waveIn = new-object NAudio.Wave.WasapiLoopbackCapture
      $waveOut = new-object NAudio.Wave.DirectSoundOut($defaultDeviceId, 100)
      $waveInProvider = new-object NAudio.Wave.WaveInProvider($waveIn)
      $waveProvider16 = new-object NAudio.Wave.WaveFloatTo16Provider($waveInProvider)
      $monoProvider16 = new-object NAudio.Wave.StereoToMonoProvider16($waveProvider16)
      $monoProvider16.leftVolume = 1
      $monoProvider16.rightVolume = 1
      $waveOut.init($monoProvider16)
      $waveOut.play()
      $waveIn.startRecording()
      

      detailed description
      Capture all the sound output to the new device by default:
      $waveIn = new-object NAudio.Wave.WasapiLoopbackCapture

      We output sound to the previous device by default (headphones are connected to its connector) with a delay of 100ms to prevent clicks:
      $waveOut = new-object NAudio.Wave.DirectSoundOut($defaultDeviceId, 100)

      We have a stereo to mono converter, but it only works with 16 bit format. There is also a converter in the appropriate format. Applying them sequentially, we achieve the desired result:
      $waveProvider16 = new-object NAudio.Wave.WaveFloatTo16Provider($waveInProvider)
      $monoProvider16 = new-object NAudio.Wave.StereoToMonoProvider16($waveProvider16)

      Set the volume for the right and left channels:
      $monoProvider16.leftVolume = 1
      $monoProvider16.rightVolume = 1

      Bind to the exit:
      $waveOut.init($monoProvider16)

      We start the process:
      $waveOut.play()
      $waveIn.startRecording()


    7. We go on youtube and watch a video
    8. You can stop the redirection like this:
      $waveIn.stopRecording()
      $waveOut.stop()
      
    9. Remember to return the device back to default.

    The method is not ideal: a second audio output device and a global reconfiguration are required.
    PS The approach described above had an alternative: to insert the connector into the headphone jack not completely.

    Also popular now: