Skip to content

Commit

Permalink
lab 3 task b
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktoriada26 committed Feb 27, 2024
1 parent 6f7003d commit 4ae2c10
Show file tree
Hide file tree
Showing 8 changed files with 1,114 additions and 643 deletions.
Binary file added Code/.yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions Code/azure.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const KEY = "b24ba4a82dad46ba9ee9a88ebed807f1";
6 changes: 4 additions & 2 deletions Code/dm.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ const grammar = {
vasilis: {person: "Vasilis Daniilidis"},
eva: {person:"Evaggelia Deligianni"},
eleni: {person:"Eleni Dochtsi"},
minas: {person: "Minas Daskalakis"},
george: {person: "George Mariolos"},
rasmus: { person: "Rasmus Blanck" },
victoria: {person: "Victoria Daniilidou"},
george: {person: "George Daniilidis"},
//george: {person: "George Daniilidis"},
ivan: {person:"Ivan Kostov"},
monday: { day: "Monday" },
tuesday: { day: "Tuesday" },
Expand Down Expand Up @@ -290,7 +292,7 @@ const dmMachine = setup({
params: `Your appointment has been created.`,
}],

on: {SPEAK_COMPLETE: "#DM.Done"},
on: {SPEAK_COMPLETE: "#DM.Done"}, //LIsten nlu:value=true
},},},
Done:{
on:{
Expand Down
74 changes: 74 additions & 0 deletions Code/dm3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { assign, createActor, setup } from "xstate";
import { speechstate } from "speechstate";
import { createBrowserInspector } from "@statelyai/inspect";
import { KEY } from "./azure.js";

const inspector = createBrowserInspector();

const azureCredentials = {
endpoint:
"https://northeurope.api.cognitive.microsoft.com/sts/v1.0/issuetoken",
key: KEY,

};

const settings = {
azureCredentials: azureCredentials,
asrDefaultCompleteTimeout: 0,
asrDefaultNoInputTimeout: 5000,
locale: "en-US",
ttsDefaultVoice: "en-US-DavisNeural",
speechRecognitionEndpointId: "c28746b8-2cad-48aa-ada0-7aba121e1ede"

};
const dmMachine = setup({
actions: {
listen : ({context}) =>
context.ssRef.send({
type: "LISTEN"
}),
},
}).createMachine({
context: {
count: 0,
},
id: "DM",
initial: "Prepare",
states: {
Prepare: {
entry: [
assign({
ssRef: ({ spawn }) => spawn(speechstate, { input: settings }),
}),
({ context }) => context.ssRef.send({ type: "PREPARE" }),
],
on: { ASRTTS_READY: "Listen" },
},

Listen: {
entry : "listen",
on : {
RECOGNISED : {
actions : ({event}) => console.log(event.value[0].confidence)
}
}
}
},
});

const dmActor = createActor(dmMachine, {
inspect: inspector.inspect,
}).start();

dmActor.subscribe((state) => {
console.log(state)
});

export function setupButton(element) {
element.addEventListener("click", () => {
dmActor.send({ type: "CLICK" });
});
dmActor.getSnapshot().context.ssRef.subscribe((snapshot) => {
element.innerHTML = `${snapshot.value.AsrTtsManager.Ready}`;
});
}
Loading

0 comments on commit 4ae2c10

Please sign in to comment.