question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not packaging mp3 media

See original GitHub issue

Firstly would like to thank you for making this @kerrickstaley ! My application is making Anki cards for children learning spellings, now that the schools are closing for COVID-19 in UK. I have audio files named after each word to be learned in the folder where my .py file is (using Pycharm).

When I package up and then import to Anki, I can’t get the audio files to play unless I manually find the collection.media folder in the Anki2 appdata folder (on Win10). When I unzip the Anki package in 7Zip and open the media file, the only contents are {}, so I currently think this is a packaging issue.

My code is below. The whole thing works really well when I manually add the media files but from the readme.md section on adding media, it seems they should be packaged for import too. Thanks for any insight you can offer - this will help so many people if I can get it to work (making all the spelling lists automatically into Anki cards using Text to Speech and genanki)!


#read the file into a list of words
lines_list = open('file.txt').read().splitlines()

# declare the Deck and give it a name and unique ID number
my_deck = genanki.Deck(
  2759406110,
  'Test Deck')

# Declare the Model to be used (sets the format for the cards)
my_model = genanki.Model(
  1607792720,
  'Basic (type in the answer)',
  fields=[  # These fields need to match up with the field names used inside the `Template` section below
    {'name': 'Front'},
    {'name': 'Back'},
  ],
  templates=[  # {{type:Back}} is what prompts Anki to put the box in the card for text input for your answer. Anki compares and shows a "diff" against the real answer
    {
      'name': 'Card 1',
      'qfmt': '{{Front}} {{type:Back}}',  # Question Format?
      'afmt': '{{Front}}<hr id="answer">{{type:Back}}',  # Answer Format? `Frontside` can be used instead of 'Front' if you want to display the whole front as well as the back, but this can lead to repetition
    },
  ])

mediaList = []  # declare a list to hold the names of all our media files
for l in lines_list:
    mediaName = l + '.mp3'  # generate the file name for the audio file from the word in the list
    mediaList.append(l + '.mp3')  # append the name of each media file to the list
    soundName = '[sound:' + mediaName + ']'
    print(soundName)

    my_note = genanki.Note(
      model=my_model,
      fields=[soundName , l])

    my_deck.add_note(my_note)

print(mediaList)  # show the list for debug purposes

my_package = genanki.Package(my_deck)
my_package.media_files = mediaList # Contains the list of all our media files. May need to experiment with and without square braces here
#my_package.media_files = ['actual.mp3','bicycle.mp3','business.mp3']

genanki.Package(my_deck).write_to_file('test_output.apkg')

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

4reactions
hobofancommented, Mar 24, 2020

@SimonMerrett Just ran into the same problem as you, presumably because we copy-pasted to much from the README 😅

genanki.Package(my_deck).write_to_file('test_output.apkg')

should be

my_package.write_to_file('test_output.apkg')
2reactions
Geocalicommented, Mar 21, 2020

Same problem here The files seem to be included in the .apkg file, because I can see its size increasing, however the files are not loaded into Anki i had to manually copy the files in ~/.local/share/Anki2/User\ 1/collection.media to make it work

Read more comments on GitHub >

github_iconTop Results From Across the Web

Media Player does not play mp3 in Win 7 - Microsoft Community
I copied back all my files but Media Player 12 does not play my mp3 files - it sounds like "quick-play" but the...
Read more >
What are the technical reasons behind not supporting MP3 files?
What are the differences between MP3 and WAV formats that prevent MP3 from being supported? What work would need to be done to...
Read more >
Media Server not sending album art embedded in MP3 files
It seems that my Media Server package was somehow updated to 1.8.0-2864 which does not appear to be an official release build. Perhaps...
Read more >
macos - Packaging mp3 files into Qt app - Stack Overflow
The likely problem is when you're accessing them in your code you're pointing to the path in the build directory, and not the...
Read more >
Beamer - mp3 - file does not play - TeX - LaTeX Stack Exchange
I already followed all steps in the Q&A at How to include multimedia files in beamer. My followed MMW does compile but do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found