⬆️ ⬇️

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

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



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





  1. Download and unpack the archive with the library
  2. Launch from the start menu of PowerShell ISE
  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 the default audio output device id:

     $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 audio 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
    Grab all sound output to the new device by default:

     $waveIn = new-object NAudio.Wave.WasapiLoopbackCapture 


    We output the 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 to the appropriate format. Applying them consistently, 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 exit:

     $waveOut.init($monoProvider16) 


    Run the process:

     $waveOut.play() $waveIn.startRecording() 




  7. Go to youtube and watch video
  8. You can stop the redirection as follows:

     $waveIn.stopRecording() $waveOut.stop() 
  9. Do not forget to return the default device.


The method is not perfect: a second audio output device and a global reconfiguration are required.

PS The approach described above had an alternative: insert the connector into the headphone jack not completely.


')

Source: https://habr.com/ru/post/201870/



All Articles