npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

unrealspeech-react-sdk

v1.0.3

Published

React SDK for UnrealSpeech API

Downloads

16

Readme

UnrealSpeech React SDK

The UnrealSpeech React SDK is a package that provides a set of hooks and functions to interact with the UnrealSpeech API in a React application. It simplifies the process of generating speech, creating synthesis tasks, and retrieving task status using the UnrealSpeech service.

Installation

To install the UnrealSpeech React SDK, use npm or yarn:

npm install unrealspeech-react-sdk

or

yarn add unrealspeech-react-sdk

Usage

useUnrealSpeech The useUnrealSpeech hook initializes an instance of the UnrealSpeech class with the provided API key. It returns the UnrealSpeech instance that can be used to access the UnrealSpeech API methods.

import { useUnrealSpeech } from "unrealspeech-react-sdk";

const App = () => {
  const unrealSpeech = useUnrealSpeech("YOUR_API_KEY");
};

useSynthesisTask

The useSynthesisTask hook provides a way to create synthesis tasks and retrieve their status. It returns an object containing the following properties:

  1. isLoading: Indicates whether the synthesis task creation is in progress.
  2. error: Stores any error that occurs during the synthesis task creation or status retrieval.
  3. taskId: Stores the ID of the created synthesis task.
  4. taskStatus: Stores the status of the synthesis task.
  5. createSynthesisTask: A function to create a new synthesis task.
  6. getSynthesisTaskStatus: A function to retrieve the status of a synthesis task.
import { useSynthesisTask } from "unrealspeech-react-sdk";

const App = () => {
  const {
    isLoading,
    error,
    taskId,
    taskStatus,
    createSynthesisTask,
    getSynthesisTaskStatus,
  } = useSynthesisTask("YOUR_API_KEY");

  const handleCreateTask = async () => {
    await createSynthesisTask("Hello, world!");
  };
};

useSpeech

The useSpeech hook provides a way to generate speech using the UnrealSpeech API. It returns an object containing the following properties:

  1. isLoading: Indicates whether the speech generation is in progress.
  2. error: Stores any error that occurs during the speech generation.
  3. data: Stores the generated speech data.
  4. speech: A function to generate speech.
import { useSpeech } from "unrealspeech-react-sdk";

const App = () => {
  const { isLoading, error, data, speech } = useSpeech("YOUR_API_KEY");

  const handleSpeech = async () => {
    await speech("Hello, world!");
  };
};

Example

import React, { useState } from "react";
import {
  useUnrealSpeech,
  useSynthesisTask,
  useSpeech,
} from "unrealspeech-react-sdk";

const App = () => {
  const [text, setText] = useState("");
  const unrealSpeech = useUnrealSpeech("YOUR_API_KEY");
  const {
    isLoading: isSynthesisTaskLoading,
    error: synthesisTaskError,
    taskId,
    taskStatus,
    createSynthesisTask,
    getSynthesisTaskStatus,
  } = useSynthesisTask("YOUR_API_KEY");
  const {
    isLoading: isSpeechLoading,
    error: speechError,
    data: speechData,
    speech,
  } = useSpeech("YOUR_API_KEY");

  const handleTextChange = (e) => {
    setText(e.target.value);
  };

  const handleCreateTask = async () => {
    await createSynthesisTask(text, {
      voiceId: "Scarlett",
      bitrate: "192k",
      timestampType: "word",
      speed: 0,
      pitch: 1.0,
    });
  };

  const handleGetTaskStatus = async () => {
    await getSynthesisTaskStatus(taskId);
  };

  const handleSpeech = async () => {
    await speech(text, {
      voiceId: "Scarlett",
      bitrate: "320k",
      timestampType: "sentence",
      speed: 0,
      pitch: 1.0,
    });
  };

  return (
    <div>
      <h1>UnrealSpeech React SDK Example</h1>
      <div>
        <h2>Create Synthesis Task</h2>
        <textarea
          value={text}
          onChange={handleTextChange}
          placeholder="Enter text to synthesize"
        />
        <button onClick={handleCreateTask} disabled={isSynthesisTaskLoading}>
          {isSynthesisTaskLoading ? "Creating Task..." : "Create Task"}
        </button>
        {synthesisTaskError && <p>Error: {synthesisTaskError.message}</p>}
        {taskId && <p>Task ID: {taskId}</p>}
        {taskStatus && <p>Task Status: {taskStatus.TaskStatus}</p>}
        <button onClick={handleGetTaskStatus} disabled={!taskId}>
          Get Task Status
        </button>
      </div>
      <div>
        <h2>Generate Speech</h2>
        <textarea
          value={text}
          onChange={handleTextChange}
          placeholder="Enter text to generate speech"
        />
        <button onClick={handleSpeech} disabled={isSpeechLoading}>
          {isSpeechLoading ? "Generating Speech..." : "Generate Speech"}
        </button>
        {speechError && <p>Error: {speechError.message}</p>}
        {speechData && (
          <audio controls>
            <source src={speechData.OutputUri} type="audio/mpeg" />
            Your browser does not support the audio element.
          </audio>
        )}
      </div>
    </div>
  );
};

export default App;

Configuration

The hooks and functions in the UnrealSpeech React SDK accept various options to customize the behavior of the UnrealSpeech API calls. Please refer to the UnrealSpeech API documentation for more information on the available options.

Error Handling

The hooks and functions in the UnrealSpeech React SDK handle errors that may occur during API calls. The error property in the returned objects will contain any error that occurred. Make sure to check for errors and handle them appropriately in your application.

License

This package is licensed under the MIT License. Contributing Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request on the GitHub repository. Support For any questions or support, please contact our support team at [email protected].