Browse Source

no message

master
Niko 5 years ago
commit
e959a4e94b
11 changed files with 4393 additions and 0 deletions
  1. 61
    0
      .gitignore
  2. 25
    0
      .vscode/launch.json
  3. 3
    0
      .vscode/settings.json
  4. 32
    0
      client/index.html
  5. 54
    0
      client/style.css
  6. 509
    0
      client/ws-client.js
  7. 596
    0
      lebensmittel.txt
  8. 12
    0
      server/dialogflow_cred_dem.json
  9. 2984
    0
      server/package-lock.json
  10. 24
    0
      server/package.json
  11. 93
    0
      server/ws-server.js

+ 61
- 0
.gitignore View File

@@ -0,0 +1,61 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env

# next.js build output
.next

+ 25
- 0
.vscode/launch.json View File

@@ -0,0 +1,25 @@
{
"version": "0.1.0",
"configurations": [
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome",
"url": "http://localhost:8000",
"webRoot": "${workspaceFolder}"
},

{
"type": "node",
"request": "launch",
"name": "Launch Server",
"program": "${workspaceFolder}/server/ws-server.js"
},
{
"name": "Launch index.html",
"type": "chrome",
"request": "launch",
"file": "${workspaceFolder}/client/index.html"
},
]
}

+ 3
- 0
.vscode/settings.json View File

@@ -0,0 +1,3 @@
{
"workbench.settings.openDefaultKeybindings": true
}

+ 32
- 0
client/index.html View File

@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width">

<title>Wort matcher</title>

<link rel="stylesheet" href="style.css">
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>

<body>
<h1>Speech Recognition</h1>
<p id=info>Press the button to activate microphone.</p>
<p id=query hidden>query</p>

<button>Start new test</button>
<button id="speechBtn">Speech</button>
<button onclick="getElementById('query').innerHTML = 'changed'">Change query</button>

<div>
<p class="server">Server offline</p>
<p class="output" style="font-style: italic;">... erkannte worte ...</p>
</div>

<script src="ws-client.js"></script>
</body>
</html>

+ 54
- 0
client/style.css View File

@@ -0,0 +1,54 @@
body, html {
margin: 0;
}

html {
height: 100%;
background-color: teal;
}

body {
height: inherit;
overflow: hidden;
}

h1, p {
font-family: sans-serif;
text-align: center;
}

div p {
padding: 20px;
background-color: rgba(0,0,0,0.2);
}

div {
overflow: auto;
position: absolute;
bottom: 0;
right: 0;
left: 0;
}

button {
margin: 0 auto;
display: block;
font-size: 1.1rem;
width: 170px;
line-height: 2;
margin-top: 30px;
}

@media all and (max-height: 410px) {
div {
position: static;
}
}

.phrase {
font-weight: bold;
}

.output {
font-style: italic;
}

+ 509
- 0
client/ws-client.js View File

@@ -0,0 +1,509 @@
// web speech recognition api
var SpeechRecognition = SpeechRecognition || webkitSpeechRecognition;
var SpeechGrammarList = SpeechGrammarList || webkitSpeechGrammarList;
var SpeechRecognitionEvent = SpeechRecognitionEvent || webkitSpeechRecognitionEvent;

// state management
var state = '';
var question = 0;
var rePrompt = false;
var partTwo = false;
var count = 0;
var strike = 0;

// Questions
const QUESTION_ONE = 'Ich werde Ihnen jetzt langsam eine Liste mit Worten vorlesen. Danach wiederholen Sie bitte möglichst viele dieser Worte. Auf die Reihenfolge kommt es nicht an.';
const QUESTION_ONE_PT2 = 'Vielen Dank. Nun nenne ich Ihnen die gleichen 10 Worte ein zweites mal. Auch danach sollen Sie wieder möglichst viele Worte wiederholen';
const QUESTION_TWO = 'Nennen Sie mir bitte so viel Dinge wie möglich, die man im Supermarkt kaufen kann. Sie haben dafür eine Minute Zeit.';
const QUESTION_THREE = 'Ich werde Ihnen jetzt eine Zahlenreihe nennen, die Sie mir dann bitte in umgekehrter Reihenfolge wiederholen sollen. Wenn ich beispielsweise, vier - fünf sage, dann sagen Sie bitte, fünf - vier.';

// intents
const WELCOME_INTENT = 'Default Welcome Intent';
const WELCOME_FOLLOWUP_YES = 'Default Welcome Intent - yes';
const WELCOME_FOLLOWUP_NO = 'Default Welcome Intent - no';
const MORE_TIME = 'Add Time Intent';
const MORE_TIME_YES = 'Add Time Intent - yes';
const MORE_TIME_NO = 'Add Time Intent - no';
const QUIT_INTENT = 'Quit Intent';
const FALLBACK_INTENT = 'Default Fallback Intent';
const HELP_INTENT = 'Help Intent';
const CHOOSE_QUESTION = 'Frage_Starten';
const NEXT_QUESTION = 'Nächste Frage';

// question one results
const QUESTION_ONE_ANSWERS = ['teller', 'hund', 'lampe', 'brief', 'apfel', 'apfelwiese', 'apfelwiese', 'apfelbaum', 'apfelbaum', 'und', 'hose', 'tisch', 'wiese', 'glas', 'baum'];
const QUESTION_ONE_QUESTIONS = ['teller', 'hund', 'lampe', 'brief', 'apfel', 'hose', 'tisch', 'wiese', 'glas', 'baum'];
const QUESTION_TWO_ANSWERS = [''];
const QUESTION_TWO_QUESTIONS = [''];
const QUESTION_THREE_QUESTIONS_PT1 = ['7, 2', '4, 7, 9', '5, 4, 9, 6', '2, 7, 5, 3, 6', '8, 1, 3, 5, 4, 2'];
const QUESTION_THREE_QUESTIONS_PT2 = ['8, 6', '3, 1, 5', '1, 9, 7, 4', '1, 3, 5, 4, 8', '4, 1, 2, 7, 9, 5'];
const QUESTION_THREE_ANSWERS_PT1 = ['27', '974', '6945', '63572', '245318'];
const QUESTION_THREE_ANSWERS_PT2 = ['68', '513', '4791', '84531', '597214'];

// points
var questionOnePoints = 0;
var questionTwoPoints = 0;
var questionThreePoints = 0;
var questionFourPoints = 0;
var questionFivePoints = 0;
var questionSixPoints = 0;

// tokenization
const separators = [' ', '\\\+', '-', '\\\(', '\\\)', '\\*', '/', ':', '\\\?'];

// Timers
var timerId;

// html elements
var serverPara = document.querySelector('.server');
var diagnosticPara = document.querySelector('.output');
var testBtn = document.querySelector('button');
var testBtn2 = document.getElementById('speechBtn');
var infoPara = document.getElementById('info');
var userPrompt = document.getElementById('query');

console.log(window.location.host + window.location.pathname);

// websocket to communicate with the server
var ws = new WebSocket('ws://localhost:8000/ws');

// speech recognition
var recognition = new SpeechRecognition();
recognition.lang = 'de-DE';
// recognition.interimResults = false;
recognition.maxAlternatives = 1;
recognition.continuous = true;
var answerQuery = '';
var skipRecording = false;

// speech synthesis
var speechsynth = new SpeechSynthesisUtterance();
var listSpeechsynth = new SpeechSynthesisUtterance();
var voices;

window.speechSynthesis.onvoiceschanged = function () {
voices = window.speechSynthesis.getVoices();
voices.forEach(element => {
if (element.name === 'Google Deutsch') {
speechsynth.voice = element;
listSpeechsynth.voice = element;
}
});

listSpeechsynth.rate = 0.7;
};

function startDemenzScreening () {
console.log('button clicked');
ws.send('starte demenz test');
//
// state = 'answer'
// recognizeSpeech()

//
testBtn.disabled = true;
testBtn.textContent = 'Test in progress';
infoPara.textContent = 'wait...';
}

function speak (sentence) {
speechsynth.text = sentence;
window.speechSynthesis.speak(speechsynth);
}

function testSpeechOut () {
console.log('click');
// skipRecording = true
// let utterance = new SpeechSynthesisUtterance()
// utterance.voice = voices[2]
// // utterance.rate = 0.75
// utterance.text = QUESTION_THREE
// window.speechSynthesis.speak(utterance)
//
// question = 3;
// startQuestion(question);
// state = 'answer';
speechsynth.text = 'test 123';
speechsynth.volume = 1;
speechsynth.rate = 1;
console.log(speechsynth);
window.speechSynthesis.speak(speechsynth);
console.log(window.speechSynthesis);
// speak('Niko ist der größte hurn eu west');
}

// websocket events
ws.onopen = function () {
serverPara.style.background = 'green';
serverPara.innerHTML = 'Server online';
};

ws.onmessage = function (payload) {
var dialogflowResult = JSON.parse(payload.data);
checkIntent(dialogflowResult);
document.querySelector('h1').innerHTML = dialogflowResult.intent.displayName;
};

// INTENT HANDLING
function checkIntent (result) {
switch (result.intent.displayName) {
case QUIT_INTENT:
state = 'quit';
skipRecording = true;
speak('Okay, Danke fürs Benutzen.');
break;
case WELCOME_INTENT:
state = 'detect';
// speak(result.fulfillmentText)
speak('go?');
break;
case WELCOME_FOLLOWUP_YES:
startQuestion(1);
break;
case WELCOME_FOLLOWUP_NO:
skipRecording = true;
speak('Okay, Danke fürs Benutzen.');
break;
case MORE_TIME:
state = 'detect';
speak('Brauchen Sie noch etwas Zeit?');
break;
case MORE_TIME_YES:
rePrompt = true;
state = 'answer';
speak('Alles klar');
break;
case MORE_TIME_NO:
skipRecording = true;
state = 'answer';
speak('Verstanden');
recognition.stop();
ws.send(answerQuery);
break;
case CHOOSE_QUESTION:
question = result.parameters.fields.num.numberValue;
state = 'answer';
handleQuestion();
break;
case FALLBACK_INTENT:
// if (state === 'answer') {
// handleAnswer(result.queryText)
// }
break;
default:
break;
}
}

function startQuestion (number) {
question = number;
state = 'answer';
handleQuestion();
}

// QUESTION HANDLING
function handleQuestion () {
switch (question) {
case 1:
readQuestionOne(QUESTION_ONE);
break;
case 2:
readQuestionTwo(QUESTION_TWO);
break;
case 3:
// skipRecording = true;
// speak(QUESTION_THREE);
speak(QUESTION_THREE_QUESTIONS_PT1[0]);
break;
case 4:
break;
case 5:
break;
}
}

function handleAnswer (query) {
switch (question) {
case 1:
handleAnswerToFirstQuestion(query);
break;
case 2:
handleAnswerToSecondQuestion(query);
break;
case 3:
handleAnswerToThirdQuestion(query);
break;
case 4:
break;
case 5:
break;
}
}

function handleAnswerToFirstQuestion (answer) {
var tokens = answer.split(new RegExp(separators.join('|'), 'g'));
questionOnePoints = calculatePoints(tokens, QUESTION_ONE_ANSWERS);
if (partTwo) {
partTwo = false;
startQuestion(2);
// state = 'detect'
} else {
rePrompt = false;
speak(QUESTION_ONE_PT2);
partTwo = true;
}
}

function handleAnswerToSecondQuestion (answer) {
var tokens = answer.split(new RegExp(separators.join('|'), 'g'));
questionTwoPoints = calculatePoints(tokens, QUESTION_TWO_ANSWERS);
skipRecording = true;
speak('Sie haben ' + questionOnePoints + 'Punkte');
startQuestion(3);
// state = 'detect'
}

function handleAnswerToThirdQuestion (query) {
speechsynth.rate = 0.87;
query = query.replace(' ', '');

let answerArray;
let questionArray;
if (!partTwo) {
answerArray = QUESTION_THREE_ANSWERS_PT1;
} else {
answerArray = QUESTION_THREE_ANSWERS_PT2;
}
if (query === answerArray[count]) {
strike = 0;
partTwo = false;
count++;
questionThreePoints = count + 1;
questionArray = QUESTION_THREE_QUESTIONS_PT1;
} else {
strike++;
partTwo = true;
questionArray = QUESTION_THREE_QUESTIONS_PT2;
}

if (strike === 2 || count === 5) {
speechsynth.rate = 1;
skipRecording = true;
speak('weiter geht es mit der Nächsten Frage');
startQuestion(4);
return;
}

speak(questionArray[count]);

console.log('count: ' + count + ', strike: ' + strike + ', points: ' + questionThreePoints);
}

// Question specific functions
function readQuestionOne (text) {
skipRecording = true;
speak(text);
for (let i = 0; i < QUESTION_ONE_QUESTIONS.length; i++) {
let utterance = new SpeechSynthesisUtterance();
utterance.voice = voices[2];
utterance.rate = 0.75;
utterance.text = QUESTION_ONE_QUESTIONS[i];
window.speechSynthesis.speak(utterance);
if (i === 9) {
utterance.onend = function (event) {
console.log('end of aufzählung' + i);
recognizeSpeech();
};
}
}
}

function readQuestionTwo (text) {
let utterance = new SpeechSynthesisUtterance();
utterance.voice = voices[2];
utterance.text = text;
window.speechSynthesis.speak(utterance);
console.log('q 2 started');
utterance.onend = function (event) {
window.setTimeout(
function () {
recognition.stop();
handleAnswer(answerQuery);
}, 60000);
console.log('q 2 recognition started');
recognizeSpeech();
};
}

function calculatePoints (tokens, array) {
let points = 0;
for (let i of array) {
for (let j of tokens) {
if (i === j) {
points++;
}
}
}
return points;
}

speechsynth.onend = function (event) {
switch (question) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
}
if (!skipRecording) {
recognizeSpeech();
}
skipRecording = false;
console.log('global speech end');
};

function recognizeSpeech () {
if (state === 'answer') {
var arr;
switch (question) {
case 1:
arr = QUESTION_ONE_QUESTIONS;
break;
case 2:
return;
case 3:
arr = [1, 2, 3, 4, 5, 6, 7, 8, 9];
break;
case 4:
break;
case 5:
break;
}

var grammar = '#JSGF V1.0; grammar colors; public <color> = ' + arr.join(' | ') + ' ;';
var speechRecognitionList = new SpeechGrammarList();
speechRecognitionList.addFromString(grammar, 1);
recognition.grammars = speechRecognitionList;
}
recognition.start();
console.log('reocgnition started');

recognition.onresult = function (event) {
var last = event.results.length - 1;
var speechResult = event.results[last][0].transcript.toLowerCase();

diagnosticPara.textContent += speechResult + ' ';

// console.log('Confidence: ' + event.results[0][0].confidence)

processSpeech(speechResult);
// testBtn.disabled = false
// testBtn.textContent = 'record...'
};

function processSpeech (speechResult) {
console.log('To dialogflow: ' + speechResult);
ws.send(speechResult);

let timeOut;
switch (question) {
case 1:
timeOut = 6500;
break;
case 2:
answerQuery += speechResult;
return;
case 3:
if (speechResult.includes('uhr')) {
speechResult = speechResult.replace('uhr', '');
}
timeOut = 6500;
break;
case 4:
break;
case 5:
break;
}

if (state === 'answer') {
if (timerId != undefined) {
clearTimeout(timerId);
}
answerQuery += speechResult;
timerId = window.setTimeout(
function () {
// if (!rePrompt) {
// ws.send('ich brauche noch etwas Zeit')
// } else {
console.log('recording end. Evaluate: ' + answerQuery);
handleAnswer(answerQuery);
answerQuery = '';
diagnosticPara.textContent = '';
// }
recognition.stop();
console.log('timer fallback');
}, timeOut);
} else {
console.log('recording end.');
recognition.stop();
}
}

recognition.onspeechend = function () {
// recognition.stop();
// testBtn.disabled = false;
// testBtn.textContent = 'Start new test';
};

recognition.onerror = function (event) {
testBtn.disabled = false;
testBtn.textContent = 'Start new test';
diagnosticPara.textContent = 'Error occurred in recognition: ' + event.error;
};

recognition.onaudiostart = function (event) {
// Fired when the user agent has started to capture audio.

};

recognition.onaudioend = function (event) {

};

recognition.onend = function (event) {
// Fired when the speech recognition service has disconnected.

};

recognition.onnomatch = function (event) {
// Fired when the speech recognition service returns a final result with no significant recognition. This may involve some degree of recognition, which doesn't meet or exceed the confidence threshold.
// console.log('SpeechRecognition.onnomatch')
};

recognition.onsoundstart = function (event) {
// Fired when any sound — recognisable speech or not — has been detected.

};

recognition.onsoundend = function (event) {
// Fired when any sound — recognisable speech or not — has stopped being detected.

};

recognition.onspeechstart = function (event) {
// Fired when sound that is recognised by the speech recognition service as speech has been detected.

};
recognition.onstart = function (event) {
// Fired when the speech recognition service has begun listening to incoming audio with intent to recognize grammars associated with the current SpeechRecognition.

};
}

testBtn.addEventListener('click', startDemenzScreening);
testBtn2.addEventListener('click', testSpeechOut);

+ 596
- 0
lebensmittel.txt View File

@@ -0,0 +1,596 @@
Aalsuppe
Agavendicksaft
Ahornsirup
Ajvar
Ananas
Anis
Anona
Apfel
Apfelkompott
Apfelkraut
Apfelsine
Aprikose
Artischocke
Artischockenherz
Aubergine
Auflauf
Austernpilz
Avocado
Backaroma
Backfett
Backware
Backwerk
Baiser
Balsamessig
Balsamico
Banane
Basilikum
Bauernbrot
Bergkäse
Bienenstich
Birne
Biskuitteig
Bitterschokolade
Blattsalat
Blattspinat
Blaubeere
Blaukohl
Blaukraut
Blauschimmelkäse
Blätterteig
Blumenkohl
Blutorange
Blutwurst
Blütenhonig
Bockwurst
Bohne
Bohnenkraut
Bohnensuppe
Borschtsch
Boskop
Bouillon
Bouillonwürfel
Bratapfel
Bratwurst
Broccoli
Brokkoli
Brombeere
Brot
Brotaufstrich
Brotsuppe
Brotteig
Brunnenkresse
Brühwürfel
Buchweizen
Butter
Buttercreme
Buttergebäck
Butterkäse
Butterkeks
Butterpilz
Büchsenmilch
Béchamelsauce
Béchamelsoße
Calzone
Camembert
Cannelloni
Cashew
Cashewnuss
Cayennepfeffer
Champignon
Cheddarkäse
Chester
Chesterkäse
Chicorée
Chili
Chilisauce
Chilisoße
Chinakohl
Chorizo
Christstollen
Ciabatta
Citrusfrucht
Clementine
Consommé
Cookie
Corned beef
Cornflakes
Couscous
Cranberry
Croissant
Crème fraîche
Curry
Currypulver
Currysauce
Currysoße
Currywurst
Dattel
Dattelpflaume
Datteltraube
Dauerwurst
Delikatesse
Delikatessgurke
Delikatesssenf
Dessert
Diätzucker
Dickmilch
Dill
Dinkel
Dinkelmehl
Distelöl
Dominostein
Dosenfleisch
Dosenmilch
Dosensuppe
Dosenwurst
Döner
Dörrfleisch
Dörrgemüse
Dörrobst
Dörrpflaume
Dressing
Drops
Edamer
Edamer Käse
Edelpilzkäse
Ei
Eierkuchen
Eigelb
Einbrennsuppe
Eingemachtes
Eingetropftes
Eintopf
Eisbergsalat
Emmentaler
Ente
Entenklein
Erbse
Erbsensuppe
Erdbeere
Erdnuss
Erdnussbutter
Erdnussflip
Erdnussmus
Erdnussöl
Esrom
Essen
Essig
Essiggurke
Esskastanie
Esswaren
Estragon
Feige
Feinbackwaren
Feingebäck
Feinkost
Felchen
Feldbohne
Feldfrucht
Feldsalat
Fenchel
Feta
Fett
Fettuccine
Filet
Fisch
Fischfilet
Fischkonserve
Fischrogen
Fischstäbchen
Fischsuppe
Fladenbrot
Flammkuchen
Flädlesuppe
Flädlisuppe
Fleckerlsuppe
Fleischbrühe
Fleischkonserve
Fleischsuppe
Fliederbeere
Fliederbeersuppe
Florentiner
Foie gras
Frankfurter
Frischkäse
Frittatensuppe
Frozen Yoghurt
Frucht
Fruchtbonbon
Fruchteis
Fruchtjoghurt
Fruchtjogurt
Früchtebrot
Früchtequark
Frühlingsrolle
Frühlingssuppe
Frühlingszwiebel
Frühstücksbrot
Fufu
Garnele
Gebäck
Gehacktes
Gelee
Gemüsesuppe
Gemüsezwiebel
Gerste
Gerstensuppe
Gerstlsuppe
Getreide
Gewürz
Gewürzgurke
Gorgonzola
Gouda
Graupe
Graupensuppe
Greyerzer
Grieß
Grießbrei
Grießkloß
Grießklößchen
Grießknödel
Grießmehl
Grießnockerl
Grießpudding
Grießschmarren
Grießsuppe
Grünkohl
Gulasch
Gulaschsuppe
Gurke
Gyros
Hackepeter
Hackfleisch
Hafer
Haferflocken
Hagebutte
Haifischflossensuppe
Hartkäse
Harzer
Haselnuss
Hefe
Hefezopf
Heidelbeere
Hering
Heringssalat
Hibiskustee
Himbeere
Himbeereis
Hirse
Holunderblütensirup
Honig
Honigkuchen
Honigmelone
Hummer
Hummersuppe
Hummus
Hühnerfleisch
Igel
Ingwer
Instantsuppe
Jagdwurst
Jasmintee
Jägersuppe
Joghurt
Johannisbeere
Johannisbrot
Julienne
Juliennesuppe
Kakaopulver
Kaki
Kaltschale
Kandis
Kandiszucker
Karamell
Karamellbonbon
Kardamom
Karotte
Kartoffel
Kartoffelchip
Kartoffeln
Kartoffelsuppe
Käse
Käsebrötchen
Käsekuchen
Keks
Kirsche
Kiwi
Knoblauch
Knoblauchbutter
Knoblauchöl
Knoblauchpulver
Knoblauchsalz
Knoblauchsoße
Knoblauchwurst
Kohl
Kohlroulade
Koriander
Krakauer
Krankensuppe
Krapfen
Kraut
Kräuterbutter
Kräuterkäse
Krebsfleisch
Krebssuppe
Kreplach
Kreuzkümmel
Kuchen
Kurkuma
Kümmel
Kürbis
Kürbiskern
Kürbiskernbrot
Kürbissuppe
Labskaus
Lachs
Lammfleisch
Languste
Lauch
Lauchzwiebel
Lebensmittel
Leberwurst
Lebkuchen
Lebkuchengewürz
Limburger
Limette
Linguine
Linse
Linsensuppe
Lorbeerblatt
Magermilchpulver
Mais
Maisgrieß
Maiskolben
Maismehl
Majoran
Mandarine
Mandel
Mandelkern
Mango
Maniok
Maracuja
Margarine
Marmelade
Marmorkuchen
Marzipan
Mascarpone
Matcha
Meerrettich
Mehl
Melone
Mett
Mettwurst
Milchpulver
Milchsuppe
Mohn
Mohnbrötchen
Mozzarella
Möhre
Mus
Müsli
Nektarinen
Nockerl
Nockerlsuppe
Noisette
Noisetteschokolade
Nudeln
Nugat
Nuss
Nusskuchen
Nussschinken
Nussschokolade
Obst
Obstkuchen
Okroschka
Olive
Olivenöl
Omelett
Orange
Orangeat
Oregano
Pampelmuse
Panadelsuppe
Paprika
Paranuss
Parmesankäse
Pasta
Pastete
Pastinake
Pecannuss
Pekannuss
Peperoni
Persillade
Pesto
Petersilie
Pfannkuchen
Pfeffer
Pfefferkuchen
Pferdefleisch
Pfifferling
Pfirsich
Pflaume
Pilz
Pilzsuppe
Piment
Pinienkerne
Pistazie
Pita
Pitabrot
Pizza
Plätzchen
Polenta
Pommes frites
Porridge
Posaunensuppe
Potage
Preiselbeere
Puderzucker
Puffreis
Pumpernickel
Putenfleisch
Quark
Quarkbällchen
Quarktasche
Quiche
Quitte
Radicchio
Radieschen
Rahm
Rahmsuppe
Ramen
Ravioli
Räucherlachs
Reis
Reissuppe
Remoulade
Rettich
Rhabarber
Ricotta
Rindfleisch
Rindfleischsuppe
Roggen
Roggenbrot
Rohkost
Rohrzucker
Rollmops
Romadur
Rosenkohl
Rosine
Rosinenkuchen
Rosinenschnecke
Rosmarin
Rote Beete
Rotkohl
Rotkraut
Rotschimmelkäse
Rucola
Rumfordsuppe
Rumkugel
Rübe
Rübenkraut
Rübenzucker
Salami
Salatgurke
Salbei
Salz
Salzbrezel
Salzgurke
Salzstange
Sauerkraut
Sauermilch
Sauermilchquark
Sauerrahm
Schafskäse
Schalotte
Schildkrötensuppe
Schinken
Schleimsuppe
Schmorbraten
Schnittlauch
Schokolade
Schwalbennestersuppe
Schwarzbrot
Schwarzkümmel
Schwarzwurzel
Schweinefleisch
Seitan
Sellerie
Senf
Senfgurke
Sesam
Sesambrötchen
Sesamsauce
Soja
Sojasprossen
Soljanka
Sonnenblumenkern
Spaghetti
Spargel
Spargelsuppe
Spätzle
Spekulatius
Spinat
Spreewaldgurke
Spritzgebäck
Steinpilz
Sternanis
Stollen
Stracciatella
Stutenmilch
Suppenextrakt
Suppenfleisch
Suppengrün
Suppenhuhn
Suppenknochen
Suppenspargel
Suppenwürfel
Sushi
Süßkartoffel
Süßrahm
Süßrahmbutter
Tagessuppe
Tagliatelle
Tahin
Tamarinde
Tapioka
Teewurst
Tellerfleisch
Tempeh
Terrine
Tiefkühlkost
Tiefkühlpizza
Tilsiter
Tiramisu
Toast
Tofu
Tomate
Tomatenmark
Tomatensoße
Tomatensuppe
Topinambur
Tortellini
Traube
Traubenkernöl
Urbrot
Vanille
Vanillerostbraten
Vanillezucker
Vanillinzucker
Vollkornbrot
Vollkornmehl
Vollmilchpulver
Vollmilchschokolade
Vollrohrzucker
Walnuss
Wasabi
Wassersuppe
Weichkäse
Weihnachtsgebäck
Weintraube
Weißbrot
Weißkohl
Weißkraut
Weizen
Weizengrieß
Weizenmehl
Wirsing
Wurst
Wurstbrühe
Wurstsuppe
Zaziki
Ziegenkäse
Ziegenmilch
Zimt
Zimtstange
Zitronat
Zitrone
Zitronensaft
Zucker
Zuckerguss
Zuckerrübensirup
Zwiebel
Zwiebelkuchen
Zwiebelring
Zwiebelsuppe
Äpfel
Öl

+ 12
- 0
server/dialogflow_cred_dem.json View File

@@ -0,0 +1,12 @@
{
"type": "service_account",
"project_id": "digitalerdemenztest",
"private_key_id": "1cb9f88917f63afddde619107e1ce106077c936e",
"private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQCtI/uoe6Q48Ak3\nWyVqueUJAed4trmb2Bm6UeSrYU+5IGY6zO86JyOIUDwo3CxYq38q9N3xJdI91z36\nqDtPdf2j7bSfUPo1VMgVH4ZXLb06+ddJBFxxEXLlJrGbWsKareZC2+Zoat0oOhSv\n8XQIdTBwzwC/VJs5KFmb2eh6uNsMVPhFivpQc4dkMGslreLvgQdJMDje7prRB6su\nOnAvKl1cFPpMg++e6vfeKZmoGUSv81ytV8Iu5QbTRabJvmeEba1QgTSqDdZw7EcM\nxB38Jv7TCnALmCi0pBSKiyJk/7m07b2Vj4huIYPAWsAe6cPs6m+CZEGnvCXqgU+v\nfbmX3eZbAgMBAAECggEABobZOUAz8BuIVWhfsDbCvgSu25uTwp6yVZY5twYrkbB5\nehT4naoVClHv+qBWIZ+RYyao6SrCUqd3BChsV/H8Nj5DNVBBploEUtuF3mpwfDUn\n2u5Jp89/E8lSH6ebt2X/zJxqgpwoqxgJaJqDA8CbK116Szwev9hYDGp5+4pVY5EO\njDeZBJaY97hoDFjK4EKepLr0NPHWjfkxDBGzmm1kzfqYiVXw36tEyFIeuwJR9g1A\nQyLuyRfxWZ7o6sYNvSRciwGG+uzGcQpXoFfiOgzU0dzLeje+aQHdKmQLFsJ2Wnux\n45fe+IkePWtSWpr+zd0DEw8v2RGR2tEgONresylycQKBgQDXtm+9BSX9vEaOjxaI\ne8UTtoZ3t189E7bZ3xT2k5yRNPCMfnvR5RklFIv+zsbj1ilWIUTuMufdZWEy6sca\nyeifOL/Qqz2mokFa2gBO1zVl8kawWlxoeiPEAhpDw7XGwTCXgNDQsEaItdlosZUN\n4AHXjNmfzWQFZOhX9Fwgn6O3iwKBgQDNehuT50uC4zLjTCef+jypL/PMqssoFRxH\nXDqYoRkYHx8xwzSZsvc8eTboz8iC53IEbz8IAA7wYNxdun5sKGa56b1ZyyF+HQdj\ngCuHPKrWGVSuipxq68V3AJ8jqcfWxbmwzVJs4kUCjMCts1f8D+7D/c3knH1wbT+J\nh7mN+3nmcQKBgG+kpXo/8uS7EA1ycygaXuqP+lJ1np4e2PE0K0ZfKZZhvuoIAI+m\nsffmBXrQjFGZIvXH7EQYJrcIZGEU8A2mWHYnyeb26caXjZm24JftfF6SIRHfApq0\nNFSa/fr6jNccX8jZy7lmsmrJK4eq+UkgGfP0myHBDLZZ/oKfHxtnZDV3AoGABrDR\nMRG4/bwULh6Os8DcNM4g7CsrjlSRpSk1pz6nqIdq5p3qmo6fSlLQHOiXKNwMdGSC\n8um9kso0osCt2Su/nJIl3kSlBIxBb1X/FNo+3dXZUg2lZj3jIirdA7ZFkZLCpyUo\nZ+8+PAUFSSKr3MNQDQW4rJcD5qNIDFxlCGCF6aECgYEArXlfVjBTQVZGt30hRhoC\n21CFcy++vYsDSZK8ah1cfuMXnz8rAU7qQSPXSpbQC5/Jr1+FOszeHAuvIQRVF4ZZ\neP6QVicxxurN7v+oBzWpqFnpsyxHcTUxsokATg9VXSAYLHvG1bICLem/giC56Twa\ncRvr50JjmWe2XZX8Um94WU4=\n-----END PRIVATE KEY-----\n",
"client_email": "demenz-dialogflow@digitalerdemenztest.iam.gserviceaccount.com",
"client_id": "114624321748994791485",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/demenz-dialogflow%40digitalerdemenztest.iam.gserviceaccount.com"
}

+ 2984
- 0
server/package-lock.json
File diff suppressed because it is too large
View File


+ 24
- 0
server/package.json View File

@@ -0,0 +1,24 @@
{
"name": "websocket_example",
"version": "1.0.0",
"description": "",
"main": "ws-client.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"tunnel": "ngrok http 8000"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"dialogflow": "^0.10.0",
"express": "^4.17.1",
"ngrok": "^3.1.1",
"path": "^0.12.7",
"websocket": "^1.0.28",
"ws": "^7.0.0"
},
"devDependencies": {
"standard": "^12.0.1"
}
}

+ 93
- 0
server/ws-server.js View File

@@ -0,0 +1,93 @@
// dialogflow
const dialogflow = require('dialogflow');

// server and websocket
const WebSocket = require('ws');
const http = require('http');
const path = require('path');
const express = require('express');

const webSocketsServerPort = 8000;
const serverpath = '/ws';
const app = express();
const router = express.Router();

router.get('/', function (req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});

app.use(express.static(__dirname + '/../client'));

app.use('/', router);

var server = http.createServer(app);

server.listen(process.env.port || webSocketsServerPort, function () {
console.log((new Date()) + ' Server is listening on port ' +
webSocketsServerPort);
});

const wss = new WebSocket.Server({ server: server, path: serverpath });

wss.on('connection', function connection (ws) {
ws.id = wss.getUniqueID();

console.log(ws.id + ' connected');

ws.on('message', function incoming (message) {
promptQuery(message, ws);
});

ws.on('close', function (connection) {
// close user connection
});
});

const projectId = 'digitalerdemenztest';

const sessionClient = new dialogflow.SessionsClient({
keyFilename: 'dialogflow_cred_dem.json'
});

// Send request and log result
function promptQuery (prompt, wsock) {
let sessionId = wsock.id;
let sessionPath = sessionClient.sessionPath(projectId, sessionId);

const request = {
session: sessionPath,
queryInput: {
text: {
text: prompt,
languageCode: 'de-DE'
}
}
};

sessionClient
.detectIntent(request)
.then(responses => {
const result = responses[0].queryResult;
console.log(` Query: ${result.queryText}`);
console.log(` Response: ${result.fulfillmentText}`);
if (result.intent) {
console.log(` Intent: ${result.intent.displayName}`);
} else {
console.log(` No intent matched.`);
}
wsock.send(JSON.stringify(result));

// checkIntent(result)
})
.catch(err => {
console.error('ERROR:', err);
});
}

// create unique id
wss.getUniqueID = function () {
function s4 () {
return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1);
}
return s4() + s4() + '-' + s4();
};

Loading…
Cancel
Save