Skip to content

Anboias/bookly

Repository files navigation

πŸ“š Bookly - Interactive Story Characters

A Next.js application that brings book characters to life through AI-powered voice conversations using ElevenLabs Conversational AI.

Demo

✨ Features

  • Story Feed: Vertical scrolling feed of classic literature stories
  • Character Selection: Choose from iconic characters across multiple books
  • Live Voice Conversations: Have real-time voice conversations with characters
  • Smart Voice Matching: Automatically selects appropriate voices based on character age and gender
  • Character Personalities: Each character has unique personality traits and speaking styles
  • Beautiful UI: Cinematic design with film grain effects and smooth animations

πŸ“– Available Stories & Characters

Harry Potter by J.K. Rowling

  • Harry Potter (teenager, male)
  • Hermione Granger (teenager, female)
  • Albus Dumbledore (old, male)

Pride & Prejudice by Jane Austen

  • Elizabeth Bennet (young adult, female)
  • Mr. Darcy (adult, male)

The Great Gatsby by F. Scott Fitzgerald

  • Jay Gatsby (adult, male)
  • Nick Carraway (young adult, male)
  • Daisy Buchanan (young adult, female)

Lord of the Rings by J.R.R. Tolkien

  • Frodo Baggins (young adult, male)
  • Gandalf the Grey (old, male)
  • Aragorn (middle-aged, male)

Alice in Wonderland by Lewis Carroll

  • Alice (child, female)
  • Mad Hatter (adult, male)
  • Cheshire Cat (adult, neutral)

πŸš€ Getting Started

Prerequisites

  • Node.js 18+
  • npm or yarn
  • ElevenLabs API account

Installation

  1. Clone the repository:
git clone <repository-url>
cd bookly
  1. Install dependencies:
npm install
  1. Install ElevenLabs SDK:
npm install @elevenlabs/client
  1. Set up environment variables:

Create a .env.local file in the root directory:

ELEVENLABS_API_KEY=your_elevenlabs_api_key_here

Get your API key from ElevenLabs Settings

Important: Use ELEVENLABS_API_KEY (server-side only, no NEXT_PUBLIC_ prefix) to keep your API key secure.

  1. Run the development server:
npm run dev
  1. Open http://localhost:3000 in your browser

πŸŽ™οΈ How Voice Conversations Work

Voice Mapping

Characters are assigned voices based on their age and gender:

  • Age categories: child, teenager, young-adult, adult, middle-aged, old
  • Gender categories: male, female, neutral

The system automatically combines these to create a voice key (e.g., teenager-male, old-female) and maps it to an ElevenLabs voice ID.

Character Configuration

Each character has:

  1. Age & Gender: Determines which voice to use
  2. Prompt: Defines the character's personality, background, and speaking style
  3. Introduction: The first message the character speaks when selected

Example:

{
  name: 'Harry Potter',
  age: 'teenager',
  gender: 'male',
  prompt: 'You are Harry Potter, the famous wizard...',
  introduction: 'Hello there! I\'m Harry Potter...'
}

Conversation Flow

  1. Character Selection: User scrolls through stories and taps a character
  2. Introduction: Character's introduction plays automatically
  3. Start Conversation: User clicks the character avatar to begin
  4. Live Chat: Real-time voice conversation using ElevenLabs AI
  5. End Session: Click avatar again or close button to end

🎨 Customization

Adding New Characters

Edit /src/data/stories.ts:

{
  id: 'your-character',
  name: 'Character Name',
  avatar: 'avatar-url',
  age: 'adult',
  gender: 'female',
  prompt: 'Character personality and background...',
  introduction: 'First message the character will say...'
}

Customizing Voices

Edit /src/config/voice-mapping.ts to use your own ElevenLabs voices:

'adult-female': {
  voiceId: 'your-custom-voice-id',
  name: 'Custom Voice Name',
  description: 'Voice description'
}

Find voices in the ElevenLabs Voice Library

πŸ—οΈ Project Structure

bookly/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ (story-feed)/
β”‚   β”‚   β”œβ”€β”€ story-feed.tsx        # Main feed component
β”‚   β”‚   β”œβ”€β”€ story-card.tsx        # Individual story card
β”‚   β”‚   β”œβ”€β”€ characters-carousel.tsx # Character selection
β”‚   β”‚   β”œβ”€β”€ voice-widget.tsx      # Voice conversation UI
β”‚   β”‚   └── nav-link.tsx          # Navigation component
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   β”œβ”€β”€ conversation/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ token/route.ts   # Get signed URL
β”‚   β”‚   β”‚   β”‚   └── start/route.ts   # Start session
β”‚   β”‚   β”‚   └── tts/route.ts         # Text-to-speech
β”‚   β”‚   β”œβ”€β”€ page.tsx              # Home page
β”‚   β”‚   β”œβ”€β”€ layout.tsx            # Root layout
β”‚   β”‚   └── globals.css           # Global styles
β”‚   β”œβ”€β”€ config/
β”‚   β”‚   └── voice-mapping.ts      # Voice ID mappings
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   └── stories.ts            # Story and character data
β”‚   β”œβ”€β”€ hooks/
β”‚   β”‚   └── use-mobile.ts         # Mobile detection hook
β”‚   └── utils/
β”‚       └── utils.ts              # Utility functions
β”œβ”€β”€ API_ARCHITECTURE.md           # Backend API documentation
β”œβ”€β”€ ELEVENLABS_SETUP.md           # Detailed ElevenLabs setup guide
└── README.md                     # This file

πŸ› οΈ Technologies

  • Framework: Next.js 16 (App Router)
  • Language: TypeScript
  • Styling: Tailwind CSS
  • Voice AI: ElevenLabs Conversational AI
  • Icons: Lucide React
  • State Management: React Hooks

πŸ€– Setting Up Characters

Important: Each character needs an ElevenLabs agent configured before conversations will work.

See AGENT_SETUP_GUIDE.md for detailed instructions on:

  • Creating agents in ElevenLabs dashboard
  • Configuring voice, personality, and introduction
  • Adding agent IDs to your characters

Without agent IDs, you'll see: "No agent ID configured for [Character]"

πŸ“ Development

Running Tests

npm run ts  # Type check
npm run lint  # Lint code

Building for Production

npm run build
npm start

πŸ”§ Troubleshooting

See ELEVENLABS_SETUP.md for detailed troubleshooting steps.

Common issues:

  • No audio: Check microphone permissions in browser
  • API errors: Verify API key in .env.local
  • Connection fails: Check internet connection and API credits

πŸ“„ License

This project is for educational purposes.

πŸ™ Credits

  • Stories and characters are from classic literature
  • Voice technology powered by ElevenLabs
  • Avatar images from DiceBear
  • Background images from Unsplash

About

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors