-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #243 from Deep-Blue-2013/master
Add Web Speech #242
- Loading branch information
Showing
15 changed files
with
165 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API/Using_the_Web_Speech_API | ||
const SpeechRecognition = | ||
window.SpeechRecognition || window.webkitSpeechRecognition; | ||
const SpeechRecognitionEvent = | ||
window.SpeechRecognitionEvent || window.webkitSpeechRecognitionEvent; | ||
|
||
const recognition = new SpeechRecognition(); | ||
recognition.continuous = false; | ||
recognition.lang = "en-US"; | ||
recognition.interimResults = false; | ||
recognition.maxAlternatives = 1; | ||
|
||
const synth = window.speechSynthesis; | ||
|
||
|
||
const utterThis = new SpeechSynthesisUtterance(); | ||
utterThis.pitch = 1; | ||
utterThis.rate = 1; | ||
|
||
export const webSpeech = { | ||
/** @type {import('$typedefs').OnSpeechToTextDetected} */ | ||
onSpeechToTextDetected: () => {}, | ||
|
||
start() { | ||
recognition.start(); | ||
console.log("Ready to receive a voice command."); | ||
}, | ||
|
||
/** @param {string} transcript */ | ||
utter(transcript) { | ||
setVoiceSynthesis(); | ||
utterThis.text = transcript | ||
synth.speak(utterThis); | ||
} | ||
} | ||
|
||
function setVoiceSynthesis() { | ||
if (utterThis.voice == null) { | ||
const voices = synth.getVoices(); | ||
for (let i = 0; i < voices.length; i++) { | ||
if (voices[i].name === "Microsoft Michelle Online (Natural) - English (United States)") { | ||
utterThis.voice = voices[i]; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
|
||
recognition.onresult = (event) => { | ||
const text = event.results[0][0].transcript; | ||
console.log(`Confidence: ${text} ${event.results[0][0].confidence}`); | ||
webSpeech.onSpeechToTextDetected(text); | ||
}; | ||
|
||
recognition.onnomatch = (event) => { | ||
console.log("I didn't recognize that color."); | ||
}; | ||
|
||
recognition.onerror = (event) => { | ||
console.log(`Error occurred in recognition: ${event.error}`); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
<div class="row" style="margin-top:150px;margin-left:25px;margin-right:25px;"> | ||
<div class="col-lg-8 offset-lg-2"> | ||
<p class="section-subtitle text-muted text-center pt-4 font-secondary">We craft digital, graphic and dimensional thinking, to create category leading brand experiences that have meaning and add a value for our clients.</p> | ||
<div class="d-flex justify-content-center"><a href="/login" class="btn btn-primary">New Conversation</a></div> | ||
<div class="d-flex justify-content-center"><a href="/login" class="btn btn-primary">Get Started</a></div> | ||
</div> | ||
</div> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<script> | ||
import { Container, Row, Col } from "sveltestrap"; | ||
// This page is used to initialize a new conversation for client | ||
import { page } from '$app/stores'; | ||
import { onMount } from 'svelte'; | ||
import { getAgents } from '$lib/services/agent-service.js' | ||
const params = $page.params; | ||
let agentId = "undefined"; | ||
/** @type {import('$typedefs').AgentModel[]} */ | ||
let agents = []; | ||
onMount(async () => { | ||
agents = await getAgents(); | ||
agentId = agents[0].id; | ||
}); | ||
</script> | ||
|
||
<Container fluid> | ||
<Row> | ||
<div class="col-12"> | ||
<div style="margin-top: 10vh; margin-left:10vw;"> | ||
{#each agents as agent} | ||
<div> | ||
<input | ||
class="form-check-input m-1" | ||
type="radio" | ||
name="agents" | ||
id={agent.id} | ||
value={agent.id} | ||
checked = {agentId == agent.id} | ||
on:click={() => agentId = agent.id} | ||
/> | ||
<label class="form-check-label" for={agent.id}> | ||
{agent.name} | ||
</label> | ||
<div class="mx-4">{agent.description}</div> | ||
</div> | ||
{/each} | ||
</div> | ||
</div> | ||
</Row> | ||
<Row class="text-center"> | ||
<Col> | ||
<p class="section-subtitle text-muted text-center pt-4 font-secondary">We craft digital, graphic and dimensional thinking, to create category leading brand experiences that have meaning and add a value for our clients.</p> | ||
<div class="d-flex justify-content-center"> | ||
<a href="/chat/{agentId}" class="btn btn-primary"> | ||
<i class="mdi mdi-chat" /> | ||
<span>Start Conversation</span> | ||
</a> | ||
</div> | ||
</Col> | ||
</Row> | ||
</Container> |
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
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.