This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"))); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// lib/types.ts | |
export interface RequestHandlers { | |
onResponse(response: any, info: any): void; | |
onTranscriptionUpdate(transcript: any): void; | |
onError(err: any, info: any): void; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$backgroundColor: #e8e1d3; | |
$complimentColor: #efe8e7; | |
.inputContainer { | |
display: flex; | |
flex-direction: column; | |
align-items: center; | |
width: 100%; | |
button { | |
border-radius: 50%; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
useEffect(() => { | |
// @ts-ignore (2339) | |
const audioRecorder = new window.Houndify.AudioRecorder(); | |
setRecorder(audioRecorder); | |
let voiceRequest: any; | |
audioRecorder.on("start", () => { | |
setRecording(true); | |
voiceRequest = initVoiceRequest( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const speech = new SpeechSynthesisUtterance(); | |
// Set to your language code | |
speech.lang = "en"; | |
const say = (text: string) => { | |
speech.text = text; | |
window.speechSynthesis.speak(speech); | |
}; |
OlderNewer