Skip to content

Instantly share code, notes, and snippets.

const express = require("express");
const path = require("path");
const houndifyExpress = require("houndify").HoundifyExpress;
const app = express();
require("dotenv").config({ path: "./.env" });
const PORT = process.env.PORT || 8080;
app.use(express.static(path.join(__dirname, "build")));
// lib/initVoiceRequest.ts
export default function initVoiceRequest(
recorder: any,
conversationState: object,
handlers: RequestHandlers
) {
// @ts-ignore (2339)
const voiceRequest = new window.Houndify.VoiceRequest({
//Your Houndify Client ID
// lib/types.ts
export interface RequestHandlers {
onResponse(response: any, info: any): void;
onTranscriptionUpdate(transcript: any): void;
onError(err: any, info: any): void;
}
import { useAtom } from "jotai";
import { useRef } from "react";
import { Mic, MicOff } from "react-feather";
import { recorderAtom, recordingAtom } from "./store";
import styles from "./VoiceInput.module.scss";
interface VoiceInputProps {
transcription: string;
}
export default function VoiceInput({ transcription }: VoiceInputProps) {
const [recorder] = useAtom(recorderAtom);
$backgroundColor: #e8e1d3;
$complimentColor: #efe8e7;
.inputContainer {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
button {
border-radius: 50%;
import { useCallback, useEffect, useRef, useState } from "react";
import styles from "./App.module.scss";
import initVoiceRequest from "./lib/initVoiceRequest";
import VoiceInput from "./VoiceInput";
import { useAtom } from "jotai";
import { recorderAtom, recordingAtom } from "./lib/store";
function App() {
// Keep hold of the state
const conversationState = useRef<any>(null);
const onResponse = useCallback((response: any, info: any) => {
if (response.AllResults && response.AllResults.length) {
const result = response.AllResults[0];
conversationState.current = result.ConversationState;
handleResult(result);
setTranscription("");
}
}, []);
const onTranscriptionUpdate = useCallback((transcript: any) => {
useEffect(() => {
// @ts-ignore (2339)
const audioRecorder = new window.Houndify.AudioRecorder();
setRecorder(audioRecorder);
let voiceRequest: any;
audioRecorder.on("start", () => {
setRecording(true);
voiceRequest = initVoiceRequest(
body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto",
"Oxygen", "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans",
"Helvetica Neue", sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
width: 100%;
height: 100%;
position: fixed;
const speech = new SpeechSynthesisUtterance();
// Set to your language code
speech.lang = "en";
const say = (text: string) => {
speech.text = text;
window.speechSynthesis.speak(speech);
};