Thursday, January 26, 2023

Tonie randomizer

 So recently my son has been asking for new audio on his TonieBox. Most of the time he falls asleep before the 2nd/3rd/4th chapter/audio play, so I decided to make an automated tonie-shuffle script.

A toniebox is basically an mp3 player, that lets you pick what audio you want by using little action figures (it uses rfid similar to amiibo like the switch). You can also upload your own audio with special creative tonies. I use these tonies to upload audio from his favorite tv shows.

This batch script rips the audio from "totally legally" obtained tv shows.


If there is interest (comment or contact me irl/elsewhere) I could hack together a easier to use web-version, maybe even make it take youtube videos/playlists/spotify/etc)


1
for /r %%i in (*.mkv) do ffmpeg -y -err_detect ignore_err -i "%%i" -map 0:a:0 -c copy -c:a aac "%%~ni.m4a" 


This python script gets all the tonies, wipes them, and associates each creative tonie with a specific folder. Then gets all the audio files in that folder, shuffles them, and keeps adding them until the tonie is full.

Simple script, but should provide a bunch of fresh bedtime "stories" for him to fall asleep with.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import os
import logging
import random
import ffmpeg
from tonie_api import TonieAPI

//dictionary of toniename, to sub-folder to associate specific tonies with specific shows
my_tonies = {'Blue': 'sonic prime',
             'Blue Hero': 'ultimate spiderman',
             'Gray': 'octonauts',
             'Green': 'teen titans go',
             'Pink': 'miraculous',
             'Pink Hero': 'spectacular spiderman',
             'Pirate': 'tmnt',
             'Vampire': 'marvels spiderman'
             }

path = "folder containing audio"

dry_run = True


def get_all(path):
    files = []
    count = 0

    for (dirpath, dirnames, filenames) in os.walk(path):
        for filename in filenames:
            full_path = os.path.join(dirpath, filename)
            files.append(full_path)
    print("")
    return files


# set up detailed logging
logging.basicConfig()
logging.getLogger().setLevel(logging.INFO)

api = TonieAPI('your@email.com, 'password')

# update all housholds, returns IDs of households
households = api.households_update()
for household in households:
    if households[household] == 'HOUSEHOLD NAME':
        our_household = household

print(f"Our HousedholdID: {our_household}")

# update all creative tonies, returns IDs of creative tonies
tonies = api.households[our_household].creativetonies_update()
print(tonies)

for tonie in tonies:
    print(f"\nTonie Id: {tonie} Name: {tonies[tonie]} Audio: {my_tonies[tonies[tonie]]}")
    audio_folder = f"{path}\\{my_tonies[tonies[tonie]]}"
    time_left = 5400

    if os.path.exists(audio_folder):
        if not dry_run:
            api.households[our_household].creativetonies[tonie].remove_all_chapters()
        print(f"Cleared tonie: {tonie}")
        files = get_all(audio_folder)
        random.shuffle(files)
        for file in files:
            info = ffmpeg.probe(file)
            duration = float(info['format']['duration'])
            if duration < time_left:
                time_left = time_left - duration
                filename = os.path.split(file)[1]
                print(f"Uploading: {filename} duration:{duration} left: {time_left}")
                if not dry_run:
                    api.households[our_household].creativetonies[tonie].upload(file, filename)
    else:
        print("Skipping...")

No comments:

Post a Comment

Hacking a 3ds to add parental controls

  The 3ds is an amazing piece of hardware. Especially if you hack it to add homebrew/emulators. My son has been enjoying a bit of "free...