Skip to content

SayKey Developer Guide

WenJing edited this page Oct 16, 2024 · 1 revision

SayKey Developer Guide

This guide will help you set up SayKey on your local machine for development purposes.

Dependencies

  • Python 3.10
  • Node.js (latest LTS version)
  • Git

Setting Up the Development Environment

1. Clone the Repository

git clone https://github.com/WenJing95/SayKey.git
cd SayKey

2. Create Backend Development Environment

cd ./backend
cd CT-Transformer-punctuation
pip install -e .
pip install -r requirements.txt

Start the backend server:

python main.py --sense-voice=./sherpa-onnx/model.int8.onnx --tokens=./sherpa-onnx/tokens.txt

After starting the server, you will see an output like this:

SayKey is running. Hold ctrl+q to start recording, release to recognize.
Important: Ensure the cursor is in the desired input location before using voice typing.
INFO:     Uvicorn running on http://localhost:58652 (Press CTRL+C to quit)

Follow the instructions to hold ctrl+q to start recording and release ctrl+q to recognize.

Command Line Arguments

Required Arguments:

  • --tokens: Path to the tokens.txt file needed for the speech recognition model.
  • --sense-voice: Path to the SenseVoice model.onnx file.

Optional Arguments:

  • --num-threads: Number of threads (default: 4).
  • --microphone-index: Index of the microphone to use. If not specified, the system's default microphone will be used.
  • --hotkey: Hotkey combination to start recording (default: ctrl+q).
  • --api-port: Port number for the API server (default: 58652).
  • --punc-model-dir: Directory path for punctuation model files (default: ./punc-onnx).
  • --host: Host address for the API server (default: localhost).

API Endpoints

The backend provides several APIs for interaction and configuration. All endpoints can be accessed via HTTP requests to the --api-port (default: 58652).

1. Keep-alive Endpoint
  • URL: GET /ping

  • Description: Check if the backend server is running.

  • Response:

    {
      "status": "alive"
    }
  • Example:

    curl http://localhost:58652/ping
2. List Audio Devices
  • URL: GET /list_audio_devices

  • Description: Retrieve a list of available audio input devices.

  • Response Example:

    {
      "devices": [
        {
          "index": 0,
          "name": "Microphone (Realtek High Definition Audio)",
          "is_current": true
        },
        {
          "index": 1,
          "name": "Stereo Mix (Realtek High Definition Audio)",
          "is_current": false
        }
      ]
    }
  • Example:

    curl http://localhost:58652/list_audio_devices
3. Set Audio Device
  • URL: POST /set_audio_device

  • Description: Set the microphone device by specifying its index.

  • Request Body:

    {
      "index": 1
    }
  • Successful Response Example:

    {
      "status": "success",
      "message": "success",
      "device": {
        "index": 1,
        "name": "Microphone (Realtek High Definition Audio)"
      }
    }
  • Example:

    curl -X POST http://localhost:58652/set_audio_device \
         -H "Content-Type: application/json" \
         -d '{"index": 1}'
4. Set Hotkey
  • URL: POST /set_hotkey

  • Description: Set the hotkey combination used to start and stop audio recording.

  • Request Body:

    {
      "hotkey": "ctrl+q"
    }
  • Example:

    curl -X POST http://localhost:58652/set_hotkey \
         -H "Content-Type: application/json" \
         -d '{"hotkey": "ctrl+q"}'
5. Get Hotkey
  • URL: GET /get_hotkey

  • Description: Retrieve the current hotkey configuration.

  • Response Example:

    {
      "hotkey": "ctrl+q"
    }
  • Example:

    curl http://localhost:58652/get_hotkey

Package Backend Server into an Executable (Windows Environment Needed):

./build_onefile.bat

3. Set Up Frontend Development Environment

cd ./frontend
npm install

Build and start the frontend:

npm run build
npm start

Package the frontend into an executable:

npm run build
npm run electron:build

4. Deployment

To deploy SayKey, place all files from backend\dist and frontend\release\win-unpacked into the same directory, and run Saykey.exe to start the application.