Converting audio web links to audio files

I currently have inserted audio files into my cards via a web link…
I import my cards into anki via an excel csv (the audio web link is in the rightmost column)


and then I have formatted them to be a clickable link as such:
2
However, would there be a way to convert this url link into just straight audio, which plays as soon as the other side of the card is flipped ? (I downloaded another pre made deck that does this). Ideally without having to recreate / copy paste one by one etc.
thanks

Maybe something like this:

  1. Download audio files using curl, wget, aria2, etc.
  2. Move audio files to the collection.media folder
  3. Use Find and Replace to convert urls to [sound:audio.mp3]
  4. Run Tools > Check Media

  1. Download audio files

    For example, by using curl, wget or aria2 from the command line and a list of urls in a text file

    It might be also possible to use Chrome DevTools to automatically download audio files.

    1. Open Google Chrome, navigate to google.com and open the Console panel

      https://developer.chrome.com/docs/devtools/console/reference/

    2. Copypaste this code

      Code
      URLS_TO_DOWNLOAD = `
      
      https://upload.wikimedia.org/wikipedia/commons/3/3d/En-us-book.ogg
      https://upload.wikimedia.org/wikipedia/commons/1/1e/En-uk-a_cat.ogg
      https://upload.wikimedia.org/wikipedia/commons/4/47/En-uk-a_dog.ogg
      
      `;
      
      function save(data, filename){
          if (!data) {
              console.error('ERROR: no data')
              return;
          }
      
          a = document.createElement('a');
          a.download = filename;
          a.href = window.URL.createObjectURL(data);
          a.dataset.downloadurl = ['application/octet-stream', a.download, a.href].join(':');
          a.click();
      }
      
      function sleep(ms) {
          return new Promise(resolve => setTimeout(resolve, ms));
      }
      
      URLS_TO_DOWNLOAD = URLS_TO_DOWNLOAD.trim().split('\n')
      for (let url of URLS_TO_DOWNLOAD) {
          console.log(url);
          await fetch(url).then((response) => {
              return response.blob();
          }).then(blob => {
              let filename = url.split('/').pop();
              save(blob, filename);
          }).catch((err) => {
              console.log('ERROR:', err);
          });
      
          await sleep(1000);
      }
      
      
    3. Replace URLS_TO_DOWNLOAD with new urls and press Enter to run it

    4. Agree to download multiple files

    image

  2. Move audio files to the collection.media folder

    https://docs.ankiweb.net/files.html#file-locations

  3. Use Find and Replace to convert mp3 urls to [sound:audio.mp3]

    https://docs.ankiweb.net/browsing.html#find-and-replace

    Find: https?://.+?/([^ /]+\.mp3)
    Replace: [sound:${1}]
    Treat input as regular expression - Yes

  4. Run Tools > Check Media

    https://docs.ankiweb.net/media.html#checking-media

2 Likes

Another option is to have [sound:http://…] on your cards, then use something like Localize Media - AnkiWeb

2 Likes

Thank you man this is an awesome solution - however only now it doesn’t play automatically when opening up if I use ankiweb or ankidroid (since the files are local files I guess)

Thank you, but I forgot about the Localize Media add-on, the add-on will also take care of possible duplicates with the same filename and should be more easy to use.

About AnkiWeb, I think it’s not possible due to the browser’s autoplay blocking policy.

About AnkiDroid, it should behave the same way as the desktop version, check the deck’s options - it’s accessible from the context menu (with a long tap) or from the overview screen.

https://docs.ankidroid.org/#deckOverview

By default, Anki automatically plays audio on the front and back of cards. If you check “Don’t play audio automatically”, Anki will not play audio …

https://docs.ankiweb.net/deck-options.html#audio

Maybe also install the latest AnkiDroid version from GitHub (if you’re on 2.15.6 from Google Play that was last updated on Jul 14, 2021).

https://github.com/ankidroid/Anki-Android/releases

Thanks,
I think I’ve got it working now…I added another template field for the sound file, as well as keeping that URL link for ankiweb for when I use that.
Thank you for all your help on this .

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.