'Change name of audio file downloaded from youtube-dl

I am writing a shell script to download audio.

I used youtube-dl -f 'bestaudio[ext=m4a]' <myurl> The resulting file is the title along with-mSc76Q90C4.m4a where m4a is the format

I would like to set the filename during download and also have it in .wav format

PS: To covert to .wav, I tried youtube-dl -f 'bestaudio[ext=wav]' <myurl> but it did not seem to work. Error thrown is basically - cannot use specified format.

Here is the relavent part of my shell script

   `read -p "Copy and paste the YouTube url" URL
    echo $URL
    read -p "Enter the song name" SONG
    youtube-dl -f 'bestaudio[ext=m4a]' $URL`  

I would like the string in $SONG to be the filename.

So if $SONG = "mysongname" I want the file to be mysongname.wav



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source