Showing posts with label toniebox. Show all posts
Showing posts with label toniebox. Show all posts

Wednesday, December 13, 2023

Tonie Weather

 So my son loves his tonie so much for listening to his favorite shows: blog post about that project here


I thought it would be cool to make one of his tonies tell him the weather for the day. So I threw this script together to generate a "text to speech" weather forecast for the day, and clothing recommendations for him to dress himself.

It runs every day to get the current weather, and uses the hourly high/lows and precipitation data to recommend what to wear. He wakes up in the morning, puts the yeti tonie on the box, and then knows exactly what to wear for the day.

He loves it.




Here is the code: https://github.com/spiffomatic64/tonie_sync/blob/master/tonie_weather.py


 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
from noaa_sdk import NOAA
import json
from gtts import gTTS
import shutil
from pprint import pprint
from datetime import datetime, timedelta


def get_temp(temp, low):
    temps = {100: "Very hot, Wear a Tshirt and shorts",
             85: "Hot, Wear a Tshirt and shorts",
             75: "Warm, Wear a Tshirt and shorts",
             65: "Nice, Wear a Tshirt and shorts",
             50: "Cool, Wear a Tshirt and pants",
             40: "Cold, Wear a Long Sleeves shirt and pants",
             30: "Very Cold, Wear a Long Sleeves shirt and pants"}

    for t in temps:
        if temp > t:
            if low < 65:
                temp_data = temps[t].replace("shorts","pants")
            return temp_data


def get_forcast(forecast_data, hourly_data):
    json_formatted_str = json.dumps(forecast_data, indent=2)
    print(json_formatted_str)

    tomorrow = datetime.now() + timedelta(1)
    tomorrow_string = tomorrow.strftime("%Y-%m-%d")
    # print(tomorrow_string)
    max = 0
    min = 100
    for hour_data in hourly_data:
        if hour_data['startTime'][:10] == tomorrow_string:
            hour = int(hour_data['startTime'][11:13])

            if hour > 6 and hour < 17:
                # print(hour)
                if hour_data['temperature'] > max:
                    max = hour_data['temperature']
                if hour_data['temperature'] < min:
                    min = hour_data['temperature']

    print(f"High: {max} Low: {min}")
    temp = get_temp(forecast_data['temperature'], min)
    forcast_string = (f"{forecast_data['name']} will be {temp}. " +
                      f"The forecast is {forecast_data['detailedForecast']} " +
                      f"The Low will be {min}")
    return forcast_string


n = NOAA()
res = n.get_forecasts('19067', 'US', type="forecast")
res2 = n.get_forecasts('19067', 'US', type="forecastHourly")
forecast = get_forcast(res[2], res2)
print(forecast)

myobj = gTTS(text=forecast, lang="en", slow=True)

# Saving the converted audio in a mp3 file named
# welcome
path = "I:\\audio\\weather"
filename = "weather"
ext = "mp3"

myobj.save(f"{path}\\{filename}0.{ext}")
for num in range(1, 3):
    shutil.copy(f"{path}\\{filename}0.{ext}", f"{path}\\{filename}{num}.{ext}")

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...")

Action figure vehicles

At this point I've printed a ton of custom/stock action figures. I figured they needed some vehicles. Happy kid for scale. Motorcycle Je...