s2s-voice
v1.0.0
Published
A simple Speech-to-Speech library using Pollinations AI for Text-to-Speech and Speech-to-Text in the browser
Maintainers
Readme
s2s-voice
A simple Speech-to-Speech library using Pollinations AI for Text-to-Speech (TTS) and Speech-to-Text (STT) in the browser. Works in React or plain JavaScript.
Install
npm install s2s-voiceImport the Library
import { playVoice, startSpeechToText, VOICES } from "s2s-voice";Features
- Text-to-Speech (TTS): Convert text into human-like voice audio
- Speech-to-Text (STT): Capture user speech and convert it into text
- Works directly in React or any browser environment
- Lightweight, simple, and easy to integrate
Available Voices
You can select from the following voices when using playVoice:
export const VOICES = [
"alloy", "serena", "aria", "luna", "kai",
"milo", "nova", "sophia", "zen", "clio"
];Default voice: "alloy"
Usage Examples
1. Text-to-Speech (TTS)
playVoice("Hello world", "alloy"); // default
playVoice("Hi there!", "serena"); // using another voicetext→ The text you want to speakselectedVoice→ Optional, default"alloy"
2. Speech-to-Text (STT)
startSpeechToText((recognizedText) => {
console.log("You said:", recognizedText);
});callback→ Function that receives the recognized text
3. Example in React
import React from "react";
import { playVoice, startSpeechToText, VOICES } from "s2s-voice";
function App() {
const handleSpeech = () => {
startSpeechToText((text) => {
console.log("Recognized:", text);
playVoice(`You said: ${text}`, VOICES[1]); // "serena"
});
};
return (
<div>
<button onClick={handleSpeech}>Start Speech-to-Speech</button>
</div>
);
}
export default App;Quick Reference / Commands
| Task | Command |
| ------------------------ | ------------------------------------------------------------ |
| Install package | npm install s2s-voice |
| Import functions | import { playVoice, startSpeechToText, VOICES } from "s2s-voice" |
| Play text as speech | playVoice("Hello world", "voiceName") |
| Start speech recognition | startSpeechToText(callback) |
| List available voices | console.log(VOICES) |
Notes
- Works only in modern browsers
- Default voice:
"alloy" - Can be used directly in React or plain JS projects
- Speech recognition runs once per call; continuous recognition not supported
