Bedtime Sloth:Gemma 在你的電腦上為今晚創作故事
Bedtime Sloth: a story for tonight, written by Gemma on your own computer
Bedtime Sloth 在本機運行 Gemma 3 4B,按孩子姓名、場景及喜好生成睡前故事,並以 Piper 逐段朗讀,配上夜間聲音。下載模型和語音後,應用程式毋須連接互聯網;孩子姓名及故事均留在電腦上,故事亦可儲存為文字或日後重播。
This is a submission for the Hacktoberfest Open-Source AI Challenge Week 3: Slow and Steady
What I Built
Bedtime is when parents are most tired and children most want one more story. Bedtime Sloth makes that part lazy. You type a child's name, pick a place, and press one button. It writes a new calm story, reads it slowly, and plays the sounds of the night. All of it runs on your own computer.
Here is what you can set before you press the button:
- Who it is for, and an optional favourite thing to include, like "a red scarf and a sleepy owl".
- Where it happens: Forest, Ocean, Space, Gentle dragons, Night trains or Clouds. Each place changes the colour of the night sky.
- How long: 3, 5 or 8 minutes, and how it should feel (Gentle, Very sleepy, Cozy and warm).
- How slowly it is read: Slow, Slower or Very slow.
- The sounds of the night: rain, ocean, forest night, fireplace, wind or silence.
It is built for a dark room. The sounds fade out on a sleep timer, a Night light switches the screen to warm colours, Screen off turns it fully black, and the controls fade away on their own. At the end you can continue the story tomorrow night, save it as text, or delete it. Every story is saved on the computer, so a favourite can be replayed.
The people who get to be lazier are tired parents, carers and babysitters who do not have to invent a story every night, and anyone who would rather not send a child's name and favourite things to a cloud app.
Demo
The video shows a full run on my laptop: the settings, Gemma writing a story called "Cloud Dreams", and the night sounds, timer, night light and screen off. The narration I added in the video is synthetic (made with the open-source Piper text-to-speech) and the background music was generated for the video.
Hosted copy: https://bedtime-sloth.onrender.com/ runs on Render's free tier, which cannot run a language model, so it tells a short built-in tale and the browser's voice reads it. The real experience, with Gemma writing the story, is the local one.
Code
Bedtime Sloth
A bedtime story written for your child tonight, read slowly in a calm voice, with the sounds of the night. It runs on your own computer, so it works with no internet, and the child's name and every story stay on your machine.
Built for the Hacktoberfest 2026 Open-Source AI Challenge, Week 3 (theme: Slow and Steady).
The problem
Bedtime is the part of the day when parents are most tired and children most want "one more story". Books run out, repeating the same tale gets dull, and story apps usually need an account, an internet connection and a subscription, and they send your child's name and interests to someone else's server.
What Bedtime Sloth does
| Feature | Detail |
|---|---|
| A new story every night | Gemma writes 8, 12 or 18 short paragraphs (about 3, 5 or 8 minutes) from a name, a place, an optional favourite thing and |
…
How I Built It
- The storyteller: Gemma 3 4B (open weights), run locally with Ollama. The system prompt sets the tone: gentle and safe, nothing scary, every small worry solved kindly, slower and quieter towards the end, and the child falls asleep in the last paragraph.
- The voice: each paragraph is read by Piper, an open-source text-to-speech model, and the next one is prepared while the current one plays. If Piper is not installed, the browser's own voice reads the story.
- The sounds: rain, ocean, forest night, fireplace and wind are made live in the browser with the Web Audio API, from filtered noise and oscillators. There are no sound files.
- The rest: one Python standard-library server and one HTML file. No framework, no packages for the server.
A bug that taught me something. My first version asked Gemma for strict JSON. Sometimes a small model answers in a shape you did not plan for, and my app quietly fell back to a built-in tale. I only noticed because the screen said "(built-in story)" on a recording I thought was a Gemma story. The fix was to stop being strict:
- the prompt now asks for plain text, a title on the first line and paragraphs separated by blank lines
- the parser accepts plain text, JSON with other key names, markdown, numbered paragraphs, or one long block that it splits into paragraphs
- it retries once with a simpler prompt
- when it still has to fall back, a red banner says why, and
python server.py --testchecks the model
I tested the parser against a fake model that answered in nine different ways, including a missing model, an out-of-memory error and a refused connection. I have not tried every Gemma answer, so the banner stays.
Why Does Open Innovation Matter?
A bedtime app learns a child's name, what they love and when they go to sleep. With an open-weight model, all of that stays on the computer. The model, the voice and the sounds all run locally, so once the model and the voice are downloaded, nothing in the app needs the internet. A closed API cannot promise that.
It also changes the cost. A story every night, for years, would normally mean a subscription or a per-call fee. Here the cost of one more story is electricity. I can swap the model with one setting (BS_MODEL), and in future I could fine-tune a small model on a family's own favourite stories. I have not done that part yet.
There is a trade-off. A 4B model sometimes writes an odd line or a weak ending, and a prompt cannot guarantee a story is suitable for every child. My advice in the README is to read a story first if the child is sensitive. I would rather say that than pretend the model is perfect.
My Agent Session
I built this with Claude in a chat window, not in a coding-agent tool, so there is no agent session file to embed. I used it for the code, the README and a first draft of this post. I ran the app, found the fallback bug, recorded the demo and decided what to keep.
The Lazy Payoff
The effort that disappears is the part at the start of bedtime: thinking of a story, then reading it aloud for five or ten minutes. With Bedtime Sloth it is typing a name and pressing one button. In my screen recording (a 3 minute story on my laptop with 24 GB of RAM), the story appeared about five seconds after I pressed the button. A 3 minute story is 8 short paragraphs.
Who used it this week: My niece asked for a story about her red scarf, and fell asleep before the last paragraph."
Prize Categories
- Best Use of Gemma: Gemma 3 4B runs locally through Ollama and writes every story the app tells.
- Best Use of Render: The web app and story player are hosted on Render from a Docker blueprint in the repo. The model does not run on Render, so this category is only for the front end.
來源:DEV Community · dev.to


