Search code examples
audiodirection

Determine directional sound of sound stream


I am born with Single-Sided Death which, in short, means that you're death on one of your ears. Only being able to hear on one ear, makes you lose the ability to hear direction and distance of sound.

I have wondered whether it is possible to determine direction of a sound given a stereo stream of sound. For simplification, just for two channels (left and right) and with the assumption that there does not exist background noise.

What would be a good initial strategy to cope with this problem?

Thanks in advance.


Solution

  • This seems like a interesting problem. Also since this is a hypothetical scenario, the solution/ idea given below is also probable and will depend upon lots of factors.

    Considering we have a stereo audio , using pydub we can split that into two mono channels using:

    AudioSegment(…).split_to_mono()
    Splits a stereo AudioSegment into two, one for each channel (Left/Right). Returns a list with the new AudioSegment objects with the left channel at index 0 and the right channel at index 1.

    Then we can figure out which channel is loudest using

    AudioSegment(…).split_to_mono()
    Splits a stereo AudioSegment into two, one for each channel (Left/Right). Returns a list with the new AudioSegment objects with the left channel at index 0 and the right channel at index 1.

    Then we measure loudness in each channel using:

    AudioSegment(…).rms A measure of loudness. Used to compute dBFS, which is what you should use in most cases. Loudness is logarithmic (rms is not), which makes dB a much more natural scale.

    So for test, I used a stereo music wave file and split to two mono channels and checked its loudness to see which channel is loudest.

    from pydub import AudioSegment
    sound = AudioSegment.from_file("audio.wav")
    split_sound = sound.split_to_mono()
    
    left_loudness = split_sound[0].rms
    right_loudness = split_sound[1].rms
    

    Output

    >>> left_loudness
    7030
    >>> right_loudness
    6993
    >>>