Ive been revisiting this, and I believe there is a more official way for doing it. Internally our media gallery component calls an instance of the Tainacan embed class, which actually use a WordPress filter to create the HTML <audio>
tag. This means you could do something even more specific like:
add_filter('wp_embed_handler_audio', function($audio, $attr, $url, $rawattr) {
if ( ! empty( $attr['width'] ) ) {
$dimensions = sprintf( 'width="%d" ', (int) $attr['width'] );
}
$audio = sprintf('<audio controls="" controlslist="nodownload" src="%s" %s></audio>', esc_url( $url ), $dimensions);
return $audio;
}, 9, 4);
You might wanna play with the ‘9’ value there, which is the priority of the filter, maybe 11 instead of 9 since our own code uses 10.