Pass a PHP variable (loop-audio.php) to jQuery function (js/script.js)

In general, this function lets you localize your JS strings, but you can also use it to set global JS variables:

function set_my_js_var() {
    // logic here for returning the right JS var
    $myVar = "Hello World";
    return $myVar;
}
function load_fe_scripts() {
    wp_enqueue_script( 'global-js-var', get_template_directory_uri() . '/js/my_file.js' );
    $localize_array = array(
        'my_js_var' => set_my_js_var()
    );
    wp_localize_script( 'global-js-var', 'my_global', $localize_array );
}
add_action('wp_enqueue_scripts', 'load_fe_scripts');

You can now acces the var in your JS File by my_global.my_js_var