Tolan - 立群

zlwu b98973b4a4 提交 пре 1 година
.history dd667101ef first commit пре 1 година
backend dd667101ef first commit пре 1 година
doubao-api dd667101ef first commit пре 1 година
frontend b98973b4a4 提交 пре 1 година
logs b98973b4a4 提交 пре 1 година
scripts dd667101ef first commit пре 1 година
提示词包 dd667101ef first commit пре 1 година
.DS_Store dd667101ef first commit пре 1 година
.gitignore b98973b4a4 提交 пре 1 година
API接口文档.md dd667101ef first commit пре 1 година
README.md dd667101ef first commit пре 1 година
start.sh dd667101ef first commit пре 1 година
test_recording.html dd667101ef first commit пре 1 година
test_websocket.html dd667101ef first commit пре 1 година
技术框架和建设方案.md dd667101ef first commit пре 1 година
生成进度跟踪.md dd667101ef first commit пре 1 година
部署指南.md dd667101ef first commit пре 1 година
需求分析书.md dd667101ef first commit пре 1 година
需求文档.md dd667101ef first commit пре 1 година

README.md

Tolan - Real-time AI Voice Conversation Interface

Tolan is a web-based real-time English conversation interface powered by Doubao AI. It enables users to have natural voice conversations with AI through an intuitive web interface featuring voice input, real-time audio processing, and AI-generated speech responses.

Features

  • 🎤 Voice Input: Press and hold to speak, release to send
  • 🤖 AI Conversation: Powered by Doubao real-time voice AI model
  • 🔊 Audio Playback: Real-time AI voice responses
  • 🎨 Interactive UI: Animated character with visual feedback
  • ⚡ Real-time Processing: WebSocket-based communication
  • 🌐 Web-based: Accessible through any modern browser

Technology Stack

Backend

  • Framework: FastAPI with WebSocket support
  • Audio Processing: librosa, pydub, soundfile
  • AI Integration: Doubao API (ByteDance)
  • Language: Python 3.9+

Frontend

  • Framework: React with TypeScript
  • State Management: Redux Toolkit
  • Audio Visualization: Custom audio visualizer component
  • Build Tool: Create React App

Prerequisites

  • Node.js >= 16.0.0
  • Python >= 3.9.0
  • FFmpeg (for audio processing)

Installing FFmpeg

macOS:

brew install ffmpeg

Linux (Ubuntu/Debian):

sudo apt update && sudo apt install ffmpeg

How to Run

Quick Start (Recommended)

Use the automated startup script to run both frontend and backend:

./start.sh start

This will:

  • Install all dependencies
  • Set up virtual environments
  • Start both frontend (port 3000) and backend (port 8765)
  • Display service status and URLs

Manual Setup

1. Backend Setup

cd backend

# Create virtual environment
python3 -m venv venv
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Run the backend
python run.py

2. Frontend Setup

cd frontend

# Install dependencies
npm install

# Start development server
npm start

Environment Configuration

Create a .env file in the backend directory with your API credentials:

DOUBAO_API_KEY=your_doubao_api_key_here
DOUBAO_BASE_URL=https://api.doubao.com

How to Test

To run the tests for this project, execute the following command in your terminal:

# Navigate to backend directory
cd backend

# Activate virtual environment
source venv/bin/activate

# Run specific test file
pytest test_main.py

# Run all tests
pytest

# Run tests with coverage
pytest --cov=src tests/

API Endpoints

WebSocket

  • URL: ws://localhost:8765
  • Protocol: Real-time audio streaming and AI conversation

REST API

  • Health Check: GET /health
  • API Documentation: GET /docs (FastAPI auto-generated)

Usage

  1. Open the Application: Navigate to http://localhost:3000
  2. Start Conversation: Press and hold the voice button
  3. Speak: Say something in English while holding the button
  4. Release: Let go of the button to send your audio
  5. Listen: Wait for the AI response to play automatically
  6. Continue: Repeat the process for ongoing conversation

Service Management

Using the Startup Script

# Start all services
./start.sh start

# Check service status  
./start.sh status

# View logs
./start.sh logs

# Stop all services
./start.sh stop

# Restart services
./start.sh restart

# Clean up processes
./start.sh cleanup

Manual Service Management

# Stop all related processes
pkill -f "react-scripts"
pkill -f "run.py"

# Check port usage
lsof -ti:3000  # Frontend
lsof -ti:8765  # Backend

Development

Project Structure

Tolan/
├── backend/           # Python backend (FastAPI + WebSocket)
├── frontend/          # React frontend
├── scripts/           # Deployment and utility scripts
├── logs/             # Application logs
└── start.sh          # Main startup script

Code Quality

The project includes:

  • Linting: flake8, black for Python; ESLint for TypeScript
  • Type Checking: mypy for Python; TypeScript for frontend
  • Testing: pytest for backend; Jest for frontend

Troubleshooting

Common Issues

  1. Port Already in Use:

    ./start.sh cleanup
    
    1. Audio Not Working: Ensure FFmpeg is installed and microphone permissions are granted

    2. API Connection Failed: Check your .env file and Doubao API credentials

    3. Dependencies Issues:

      ./start.sh setup  # Re-setup environment
      

Logs

  • Frontend: logs/frontend.log
  • Backend: logs/backend.log

License

This project is licensed under the MIT License.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests for new functionality
  5. Submit a pull request

Support

For questions and support, please refer to the API documentation or create an issue in the repository.