Prerequisites

To get the most out of this guide, you’ll need to:

You should have installed Node.js (version 18.10.0 or higher).

Installation

Set the API key as an environment variable

.env
JIGSAWSTACK_API_KEY='your-api-key'

Usage

Let’s use AI scrape to scrape an amazon product page.

pages/api/tts.ts
import type { NextApiRequest, NextApiResponse } from "next";
import { JigsawStack } from "jigsawstack";

const jigsawstack = JigsawStack(); // API key will be read from environment

export default async (req: NextApiRequest, res: NextApiResponse) => {
  try {
    const result = await jigsawstack.audio.text_to_speech({
      text: "Hello, how are you doing?",
    });

    const data = result.blob();

    res.status(200).json({
      success: true,
    });
  } catch (error) {
    return res.status(400).json(error);
  }
};