KT AI MAKERS KIT 사용설명서 (Node JS 편).indd

Similar documents
GiGA Genie AI API 서비스가이드 <GiGA Genie AI 음성인식 API> 1 / 21

Modern Javascript

untitled

Polly_with_Serverless_HOL_hyouk

Analytics > Log & Crash Search > Unity ios SDK [Deprecated] Log & Crash Unity ios SDK. TOAST SDK. Log & Crash Unity SDK Log & Crash Search. Log & Cras

C H A P T E R 2

Javascript.pages

Todo list Universal app

구로구민체육센터 여성전용 기구필라테스 강좌 신설 구로구시설관리공단은 신도림생활체육관에서 2014년도부터 시행하여 주민의 큰 호응을 얻고있는 기구필라 테스 강좌를 일자로 구로구민체육센터에 확대 시행하게 되었습니다. 구로구 관내 고객들의 니즈를 반영한 기

BEef 사용법.pages

28 THE ASIAN JOURNAL OF TEX [2] ko.tex [5]

OCaml

SRC PLUS 제어기 MANUAL

airDACManualOnline_Kor.key

untitled

T100MD+

PowerPoint 프레젠테이션

Microsoft PowerPoint - web-part03-ch19-node.js기본.pptx

인켈(국문)pdf.pdf

( )부록


CONTENTS 1. Approval Revision Record Scope Numbering of product Product Part No Lot. No Absolu

Microsoft PowerPoint - User Manual pptx

목차 후면 패널 연결... 3 전면 패널 컨트롤... 3 리모트 컨트롤... 4 연결하기... 5 네트워크 연결... 5 문자 입력... 5 조작 설명... 6 입력... 6 설정... 6 중요! CXN은 주로 소프트웨어 기반의 제품으로 새로운 기능과 업데이트는 수시로

歯mp3사용설명서

untitled

<30352D30312D3120BFB5B9AEB0E8BEE0C0C720C0CCC7D82E687770>

Mobile Service > IAP > Android SDK [ ] IAP SDK TOAST SDK. IAP SDK. Android Studio IDE Android SDK Version (API Level 10). Name Reference V

고급 프로그래밍 설계

03장.스택.key

PowerPoint 프레젠테이션

<30302DB8E9C1F62DB8F1C2F E687770>

PowerPoint 프레젠테이션

chap01_time_complexity.key

int main(void) int a; int b; a=3; b=a+5; printf("a : %d \n", a); printf("b : %d \n", b); a b 3 a a+5 b &a(12ff60) &b(12ff54) 3 a 8 b printf(" a : %x \

12-file.key

CD-RW_Advanced.PDF

untitled

PowerPoint 프레젠테이션

JMF2_심빈구.PDF

API STORE 키발급및 API 사용가이드 Document Information 문서명 : API STORE 언어별 Client 사용가이드작성자 : 작성일 : 업무영역 : 버전 : 1 st Draft. 서브시스템 : 문서번호 : 단계 : Docum

Dialog Box 실행파일을 Web에 포함시키는 방법

H3050(aap)

본책- 부속물

LXR 설치 및 사용법.doc

EMBARCADERO TECHNOLOGIES (Humphery Kim) RAD Studio : h=p://tech.devgear.co.kr/ : h=p://blog.hjf.pe.kr/ Facebook : h=p://d.com/hjfactory :

3주차_Core Audio_ key

목차 본 취급설명서의 사용법 본 사용설명서에서는 제품상에 표시된 채널명 및 버튼명, 소프트웨어의 메뉴명 등이 대괄호 ([ ]) 안에 표시됩니 (예: [MASTER] 채널, [ON/ OFF], [File] 메뉴) 시작하시기 전에 특징...3 부속품...4 시작하시기 전에

2

Microsoft PowerPoint - RPino-GOGO_datasheet.pptx

BH의 아이폰 추천 어플

(Asynchronous Mode) ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 -

JMF3_심빈구.PDF


LCD Display

untitled

chapter1,2.doc

01KRCOV-KR

3장

hd1300_k_v1r2_Final_.PDF

고객 카드 현대모비스 제품을 구입해 주셔서 대단히 감사합니다. A/S 마크란? 공업 진흥청이 애프터 서비스가 우수한 업체를 선정, 지정하는 마크로 애프터 서비스 센터 운영관리 등 8개 분야 45개 항목의 까다로운 심사로 결정됩니다. 주의 : 본 제품의 디자인 및 규격은

1

HW5 Exercise 1 (60pts) M interpreter with a simple type system M. M. M.., M (simple type system). M, M. M., M.

, ( ),, ( ), 3, int kor[5]; int eng[5]; int Microsoft Windows 4 (ANSI C2 ) int kor[5] 20 # define #define SIZE 20 int a[10]; char c[10]; float

[ 융합과학 ] 과학고 R&E 결과보고서 뇌파를이용한곤충제어 연구기간 : ~ 연구책임자 : 최홍수 ( 대구경북과학기술원 ) 지도교사 : 박경희 ( 부산일과학고 ) 참여학생 : 김남호 ( 부산일과학고 ) 안진웅 ( 부산일과학고 )

목차 1. 제품 소개 특징 개요 Function table 기능 소개 Copy Compare Copy & Compare Erase

MAX+plus II Getting Started - 무작정따라하기

행당중학교 감사 7급 ~ 성동구 왕십리로 189-2호선 한양대역 4번출구에서 도보로 3-4분 6721 윤중중학교 감사 7급 ~ 영등포구 여의동로 3길3 용강중학교 일반행정 9급 ~ 1300

Microsoft Word - FunctionCall

chap7.key

B _02_M_Ko.indd

λx.x (λz.λx.x z) (λx.x)(λz.(λx.x)z) (λz.(λx.x) z) Call-by Name. Normal Order. (λz.z)

DRB1598A

GT-001_j

슬라이드 제목 없음

hwp

CANTUS Evaluation Board Ap. Note

Microsoft PowerPoint - PL_03-04.pptx

140307(00)(1~5).indd

Copyright 2004 Sun Microsystems, Inc Network Circle, Santa Clara, CA U.S.A..,,. Sun. Sun. Berkeley BSD. UNIX X/Open Company, Ltd.. Sun, Su

2011년 10월 초판 c 2011 Sony Corporation. All rights reserved. 서면 허가 없이 전체 또는 일부를 복제하는 것을 금합니다. 기능 및 규격은 통보 없이 변경될 수 있습니다. Sony와 Sony 로고는 Sony의 상표입니다. G L


歯Enet_목차_.PDF

pdf

라즈베리파이 프로그래밍_130912(최종).indd


. "" "",.... :...,,....,.. :..,,,..,,...,.... 2

Interstage5 SOAP서비스 설정 가이드

PowerPoint Template

본문서는 초급자들을 대상으로 최대한 쉽게 작성하였습니다. 본문서에서는 설치방법만 기술했으며 자세한 설정방법은 검색을 통하시기 바랍니다. 1. 설치개요 워드프레스는 블로그 형태의 홈페이지를 빠르게 만들수 있게 해 주는 프로그램입니다. 다양한 기능을 하는 플러그인과 디자인

<C0CCBCBCBFB52DC1A4B4EBBFF82DBCAEBBE7B3EDB9AE2D D382E687770>

1. SNS Topic 생성여기를클릭하여펼치기... Create Topic 실행 Topic Name, Display name 입력후 Create topic * Topic name : 특수문자는 hyphens( - ), underscores( _ ) 만허용한다. Topi

11강-힙정렬.ppt

메모 Page 2

5.스택(강의자료).key

10X56_NWG_KOR.indd

슬라이드 1

s SINUMERIK 840C Service and User Manual DATA SAVING & LOADING & & /

ITVX-A-C1

Microsoft PowerPoint - 기계공학실험1-1MATLAB_개요2D.pptx

Transcription:

KT AI MAKERS KIT

03 51 20 133

3

4

5

6

7

8

9 1 2 3 5 4 11 10 6 7 8 9 12 1 6 2 7 3 8 11 12 4 9 5 10

10 1 4 2 3 5 6 1 4 2 5 3 6

12 01

13 02

03

15 04

16 05

17 06

18 07

19 08

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

52

53

54

55

56

57

58

59

60

61

62

63

64 const record=require('node-record-lpcm16'); const kwstext=['','','','']; const Speaker=require('speaker'); const fs=require('fs'); //node version check const nodeversion=process.version.split('.')[0]; let ktkws=null; if(nodeversion==='v6') ktkws=require('./ktkws'); else if(nodeversion==='v8') ktkws=require('./ktkws_v8'); //for play sample sound const soundbuffer=fs.readfilesync('../data/sample_sound.wav'); const pcmplay=new Speaker({ channels:1, bitdepth:16, samplerate:16000 //for setting kws type const kwsflag=parseint(process.argv[2]); let res=ktkws.initialize('../data/kwsmodel.pack'); console.log('initialize KWS:'+res); res=ktkws.startkws(kwsflag); console.log('start KWS:'+res); //for getting microphone input function initmic(){ return record.start({ sampleratehertz: 16000, threshold: 0, verbose: false, recordprogram: 'arecord', }) }; let mic=initmic(); mic.on('data',(data)=>{ //push pcm data to ktkws library result=ktkws.pushbuffer(data); if(result===1) { console.log("kws Detected"); //play sample sound pcmplay.write(soundbuffer); } console.log('say :'+kwstext[kwsflag]);

65 const record=require('node-record-lpcm16'); const kwstext=['','','','']; const Speaker=require('speaker'); const fs=require('fs'); //node version check const nodeversion=process.version.split('.')[0]; let ktkws=null; if(nodeversion==='v6') ktkws=require('./ktkws'); else if(nodeversion==='v8') ktkws=require('./ktkws_v8'); //for play sample sound const soundbuffer=fs.readfilesync('../data/sample_sound.wav'); const pcmplay=new Speaker({ channels:1, bitdepth:16, samplerate:16000

66 //for setting kws type const kwsflag=parseint(process.argv[2]); let res=ktkws.initialize('../data/kwsmodel.pack'); console.log('initialize KWS:'+res); res=ktkws.startkws(kwsflag); console.log('start KWS:'+res); //for getting microphone input function initmic(){ return record.start({ sampleratehertz: 16000, threshold: 0, verbose: false, recordprogram: 'arecord', }) };

67 let mic=initmic(); mic.on('data',(data)=>{ //push pcm data to ktkws library result=ktkws.pushbuffer(data); if(result===1) { console.log("kws Detected"); //play sample sound pcmplay.write(soundbuffer); } console.log('say :'+kwstext[kwsflag]);

68

69

70

71

72

73 const record=require('node-record-lpcm16'); const aikit=require('./aimakerskitutil'); const client_id=''; const client_key=''; const client_secret=''; const json_path=''; const cert_path='../data/ca-bundle.pem'; const proto_path='../data/gigagenierpc.proto'; function initmic(){ return record.start({ sampleratehertz: 16000, threshold: 0, verbose: false, recordprogram: 'arecord', silence: '10.0', }) }; let writeflag=0; //aikit.initialize(client_id,client_key,client_secret,cert_path,proto_path); aikit.initializejson(json_path,cert_path,proto_path); const ktstt=aikit.getvoice2text(); ktstt.on('error',(error)=>{ console.log('error:'+error); ktstt.on('data',(data)=>{ console.log('data:'+json.stringify(data)); ktstt.on('end',()=>{ console.log('pcm end'); record.stop(); writeflag=0; ktstt.end(); ktstt.write({reqoptions:{mode:0,lang:0} writeflag=1; const mic=initmic(); mic.on('data',(data)=>{ if(writeflag===1) ktstt.write({audiocontent:data console.log('say something');

74 const record=require('node-record-lpcm16'); const aikit=require('./aimakerskitutil'); const client_id=''; const client_key=''; const client_secret=''; const json_path=''; const cert_path='../data/ca-bundle.pem'; const proto_path='../data/gigagenierpc.proto'; function initmic(){ return record.start({ sampleratehertz: 16000, threshold: 0, verbose: false, recordprogram: 'arecord', silence: '10.0', }; })

75 let writeflag=0; //aikit.initialize(client_id,client_key,client_secret,cert_path,proto_path); aikit.initializejson(json_path,cert_path,proto_path); const ktstt=aikit.getvoice2text(); ktstt.on('error',(error)=>{ console.log('error:'+error); ktstt.on('data',(data)=>{ console.log('data:'+json.stringify(data)); ktstt.on('end',()=>{ console.log('pcm end'); record.stop(); writeflag=0; ktstt.end();

76 ktstt.write({reqoptions:{mode:0,lang:0} writeflag=1; const mic=initmic(); mic.on('data',(data)=>{ if(writeflag===1) ktstt.write({audiocontent:data console.log('say something');

77

78

79

80 const aikit=require('./aimakerskitutil'); const client_id=''; const client_key=''; const client_secret=''; const json_path=''; const cert_path='../data/ca-bundle.pem'; const proto_path='../data/gigagenierpc.proto'; //aikit.initialize(client_id,client_key,client_secret,cert_path,proto_path); aikit.initializejson(json_path,cert_path,proto_path); aikit.gettext2voiceurl({lang:0,text:'..'},(err,msg)=>{ console.log('err:'+json.stringify(err)+' msg:'+json.stringify(msg)); })

81

82

83

84

85

86

87 const Speaker=require('speaker'); const pcmplay=new Speaker({ channels:1, bitdepth:16, samplerate:16000 const aikit=require('./aimakerskitutil'); const client_id=''; const client_key=''; const client_secret=''; const json_path=''; const cert_path='../data/ca-bundle.pem'; const proto_path='../data/gigagenierpc.proto'; //aikit.initialize(client_id,client_key,client_secret,cert_path,proto_path); aikit.initializejson(json_path,cert_path,proto_path); kttts=aikit.gettext2voicestream({text:'',lang:0,mode:0 kttts.on('error',(error)=>{ console.log('error:'+error); kttts.on('data',(data)=>{ if(data.streamingresponse==='resoptions' && data.resoptions. resultcd===200) console.log('stream send. format:'+data.resoptions.format); if(data.streamingresponse==='audiocontent') { pcmplay.write(data.audiocontent); } else console.log('msg received:'+json.stringify(data)); kttts.on('end',()=>{ console.log('pcm end'); function finish(){ console.log('tts played'); }; settimeout(finish,5000);

88 const Speaker=require('speaker'); const pcmplay=new Speaker({ channels:1, bitdepth:16, samplerate:16000 const aikit=require('./aimakerskitutil'); const client_id=''; const client_key=''; const client_secret=''; const json_path=''; const cert_path='../data/ca-bundle.pem'; const proto_path='../data/gigagenierpc.proto';

89 //aikit.initialize(client_id,client_key,client_secret,cert_path,proto_path); aikit.initializejson(json_path,cert_path,proto_path); kttts=aikit.gettext2voicestream({text:'..',lang:0,mode:0 kttts.on('error',(error)=>{ console.log('error:'+error); kttts.on('data',(data)=>{ if(data.streamingresponse==='resoptions' && data.resoptions.resultcd===200) console.log('stream send. format:'+data.resoptions.format); if(data.streamingresponse==='audiocontent') { pcmplay.write(data.audiocontent); } else console.log('msg received:'+json.stringify(data));

90 kttts.on('end',()=>{ console.log('pcm end'); function finish(){ console.log('tts played'); }; settimeout(finish,5000);

91

92

93

94

95

96 const aikit=require('./aimakerskitutil'); const client_id=''; const client_key=''; const client_secret=''; const json_path=''; const cert_path='../data/ca-bundle.pem'; const proto_path='../data/gigagenierpc.proto'; //aikit.initialize(client_id,client_key,client_secret,cert_path,proto_path); aikit.initializejson(json_path,cert_path,proto_path); aikit.querybytext({querytext:'',usersession:'12345',deviceid:'hellodevie'},(err,msg)=>{ if(err){ console.log(json.stringify(err)); } else { console.log('msg:'+json.stringify(msg)); } })

97

98

99

100

101

102

103 const record=require('node-record-lpcm16'); const aikit=require('./aimakerskitutil'); const client_id=''; const client_key=''; const client_secret=''; const json_path=''; const cert_path='../data/ca-bundle.pem'; const proto_path='../data/gigagenierpc.proto'; //aikit.initialize(client_id,client_key,client_secret,cert_path,proto_path); aikit.initializejson(json_path,cert_path,proto_path); function initmic(){ return record.start({ sampleratehertz: 16000, threshold: 0, verbose: false, recordprogram: 'arecord', silence: '10.0', }) }; const query=aikit.querybyvoice((err,msg)=>{ if(err){ console.log(json.stringify(err)); } else { console.log('msg:'+json.stringify(msg)); } record.stop(); }) query.write({reqoptions:{lang:0,usersession:'12345',deviceid:'d06190914tp808iqktzq'} const mic=initmic(); mic.on('data',(data)=>{ query.write({audiocontent:data console.log('say something');

104 const query=aikit.querybyvoice((err,msg)=>{ if(err){ console.log(json.stringify(err)); } else { console.log('msg:'+json.stringify(msg)); } record.stop(); }) query.write({reqoptions:{lang:0,usersession:'12345',deviceid:'d06190914tp808iqktzq'} const mic=initmic(); mic.on('data',(data)=>{ query.write({audiocontent:data console.log('say something');

105

106

107

108

109

110 const record=require('node-record-lpcm16'); const aikit=require('./aimakerskitutil'); //node version check const nodeversion=process.version.split('.')[0]; let ktkws=null; if(nodeversion==='v6') ktkws=require('./ktkws'); else if(nodeversion==='v8') ktkws=require('./ktkws_v8'); //for playing pcm sound const Speaker=require('speaker'); const fs=require('fs'); const soundbuffer=fs.readfilesync('../data/sample_sound.wav'); const pcmplay=new Speaker({ channels:1, bitdepth:16, samplerate:16000 const client_id=''; const client_key=''; const client_secret=''; const json_path=''; const cert_path='../data/ca-bundle.pem'; const proto_path='../data/gigagenierpc.proto'; const kwstext=['','','','']; const kwsflag=parseint(process.argv[2]); function initmic(){ return record.start({ sampleratehertz: 16000, threshold: 0, verbose: false, recordprogram: 'arecord', }) };

111 ktkws.initialize('../data/kwsmodel.pack'); ktkws.startkws(kwsflag); let mic=initmic(); //aikit.initialize(client_id,client_key,client_secret,cert_path,proto_path); aikit.initializejson(json_path,cert_path,proto_path); let mode=0;//0:kws, 1:stt let ktstt=null; mic.on('data',(data)=>{ if(mode===0){ result=ktkws.pushbuffer(data); if(result===1) { console.log("kws Detected"); pcmplay.write(soundbuffer); settimeout(startstt,1000); } } else { ktstt.write({audiocontent:data } console.log('say :'+kwstext[kwsflag]); function startstt(){ ktstt=aikit.getvoice2text(); ktstt.on('error',(error)=>{ console.log('error:'+error); ktstt.on('data',(data)=>{ console.log('stt result:'+json.stringify(data)); if(data.resultcd!==200) mode=0; ktstt.on('end',()=>{ console.log('stt text stream end'); mode=0; ktstt.write({reqoptions:{mode:0,lang:0} mode=1; };

112 //aikit.initialize(client_id,client_key,client_secret,cert_path,proto_path); aikit.initializejson(json_path,cert_path,proto_path); let mode=0;//0:kws, 1:stt let ktstt=null; mic.on('data',(data)=>{ if(mode===0){ result=ktkws.pushbuffer(data); if(result===1) { console.log("kws Detected"); pcmplay.write(soundbuffer); settimeout(startstt,1000); } } else { ktstt.write({audiocontent:data }

113 console.log('say :'+kwstext[kwsflag]); function startstt(){ ktstt=aikit.getvoice2text(); ktstt.on('error',(error)=>{ console.log('error:'+error); ktstt.on('data',(data)=>{ console.log('stt result:'+json.stringify(data)); if(data.resultcd!==200) mode=0; ktstt.on('end',()=>{ console.log('stt text stream end'); mode=0; ktstt.write({reqoptions:{mode:0,lang:0} mode=1; };

114

115

116

117 const record=require('node-record-lpcm16'); const aikit=require('./aimakerskitutil'); const Speaker=require('speaker'); const fs=require('fs'); //for playing pcm sound const soundbuffer=fs.readfilesync('../data/sample_sound.wav'); const pcmplay=new Speaker({ channels:1, bitdepth:16, samplerate:16000 //node version check const nodeversion=process.version.split('.')[0]; let ktkws=null; if(nodeversion==='v6') ktkws=require('./ktkws'); else if(nodeversion==='v8') ktkws=require('./ktkws_v8'); const client_id=''; const client_key=''; const client_secret=''; const json_path='./clientkey.json'; const cert_path='../data/ca-bundle.pem'; const proto_path='../data/gigagenierpc.proto'; const kwstext=['','','','']; const kwsflag=parseint(process.argv[2]); let pcm=null; function initmic(){ return record.start({ sampleratehertz: 16000, threshold: 0, verbose: false, recordprogram: 'arecord', }) };

118 ktkws.initialize('../data/kwsmodel.pack'); ktkws.startkws(kwsflag); let mic=initmic(); //aikit.initialize(client_id,client_key,client_secret,cert_path,proto_path); aikit.initializejson(json_path,cert_path,proto_path); let mode=0;//0:kws, 1:queryByVoice let ktstt=null; mic.on('data',(data)=>{ if(mode===0){ //1) result=ktkws.pushbuffer(data); if(result===1) { //2) console.log("kws Detected"); pcmplay.write(soundbuffer); settimeout(startqueryvoice,1000); // 3) } } else { ktstt.write({audiocontent:data //4) } console.log('say :'+kwstext[kwsflag]); function startqueryvoice(){ ktstt=aikit.querybyvoice((err,msg)=>{ if(err){ console.log(json.stringify(err)); mode=0; } else { console.log('msg:'+json.stringify(msg)); const action=msg.action[0]; if(action){ const acttype=action.acttype; let mesg=action.mesg; console.log('acttype:'+acttype+' mesg:'+mesg);

119 //5) if(acttype==='99' acttype==='601' acttype==='631' acttype==='607' acttype==='608' acttype==='606' acttype==='9999'){ if(acttype==='9999'){ let textprocess=action.serviceid.split('systemmsg') [1].split(',')[0].substring(3,); mesg=textprocess.substring(0,textprocess.length-1); } //6) let kttts=aikit.gettext2voicestream({text:mesg,lang:0,mode:0 kttts.on('error',(error)=>{ console.log('error:'+error); //7) kttts.on('data',(data)=>{ if(data.streamingresponse==='resoptions' && data.resoptions. resultcd===200) console.log('stream send. format:'+data.resoptions.format); if(data.streamingresponse==='audiocontent') { pcmplay.write(data.audiocontent); } else console.log('msg received:'+json.stringify(data)); kttts.on('end',()=>{ console.log('pcm end'); mode=0;//9) } else mode=0//9) } else mode=0;//9) } ktstt.write({reqoptions:{lang:0,usersession:'12345',deviceid:'d06190914tp808iqktzq'} mode=1;//8) };

120 let mode=0;//0:kws, 1:queryByVoice let ktstt=null; mic.on('data',(data)=>{ if(mode===0){ //1) result=ktkws.pushbuffer(data); if(result===1) { //2) console.log("kws Detected"); pcmplay.write(soundbuffer); settimeout(startqueryvoice,1000); // 3) } } else { ktstt.write({audiocontent:data //4) } console.log('say :'+kwstext[kwsflag]);

121 function startqueryvoice(){ ktstt=aikit.querybyvoice((err,msg)=>{ if(err){ console.log(json.stringify(err)); mode=0; } else { console.log('msg:'+json.stringify(msg)); const action=msg.action[0]; if(action){ const acttype=action.acttype; let mesg=action.mesg; console.log('acttype:'+acttype+' mesg:'+mesg);

122 //5) if(acttype==='99' acttype==='601' acttype==='631' acttype==='607' acttype==='608' acttype==='606' acttype==='9999'){ if(acttype==='9999'){ let textprocess=action.serviceid.split('systemmsg') [1].split(',')[0].substring(3,); mesg=textprocess.substring(0,textprocess.length-1); } //6) let kttts=aikit.gettext2voicestream({text:mesg,lang:0,mode:0 kttts.on('error',(error)=>{ console.log('error:'+error);

123 }; //7) kttts.on('data',(data)=>{ if(data.streamingresponse==='resoptions' && data.resoptions. resultcd===200) console.log('stream send. format:'+data.resoptions.format); if(data.streamingresponse==='audiocontent') { pcmplay.write(data.audiocontent); } else console.log('msg received:'+json.stringify(data)); kttts.on('end',()=>{ console.log('pcm end'); mode=0;//9) } else mode=0//9) } else mode=0;//9) } ktstt.write({reqoptions:{lang:0,usersession:'12345',deviceid:'d06190914tp808iqktzq'} mode=1;//8)

124

125

126

127 const gpio=require('rpi-gpio'); const record=require('node-record-lpcm16'); const aikit=require('./aimakerskitutil'); const Speaker=require('speaker'); const fs=require('fs'); const soundbuffer=fs.readfilesync('../data/sample_sound.wav'); const pcmplay=new Speaker({ channels:1, bitdepth:16, samplerate:16000 gpio.setup(29,gpio.dir_in,gpio.edge_both); gpio.setup(31,gpio.dir_low,write); function write(err){ if(err) console.log('write Error:'+err); }; const client_id=''; const client_key=''; const client_secret=''; const json_path=''; const cert_path='../data/ca-bundle.pem'; const proto_path='../data/gigagenierpc.proto'; let pcm=null; function initmic(){ return record.start({ sampleratehertz: 16000, threshold: 0, verbose: false, recordprogram: 'arecord', }) };

128 aikit.initializejson(json_path,cert_path,proto_path); let sysstat=0; gpio.on('change',(channel,value)=>{ if(channel===29){ console.log('channel:'+channel+' value is '+value); if(value===false){ if(sysstat===0) { sysstat=1; console.log('button Pressed. Start Service'); gpio.write(31,true); pcmplay.write(soundbuffer); settimeout(startqueryvoice,1000); } } } function startqueryvoice(){ let ktstt=aikit.querybyvoice((err,msg)=>{ if(err){ console.log(json.stringify(err)); record.stop(); } else { console.log('msg:'+json.stringify(msg)); const action=msg.action[0]; if(action){ const acttype=action.acttype; const mesg=action.mesg; console.log('acttype:'+acttype+' mesg:'+mesg); if(acttype==='99' acttype==='601' acttype==='631' acttype==='607' acttype==='608' acttype==='606'){ let kttts=aikit.gettext2voicestream({text:mesg,lang:0,mode:0 kttts.on('error',(error)=>{

129 console.log('error:'+error); kttts.on('data',(data)=>{ if(data.streamingresponse==='resoptions'&& data.resoptions.resultcd===200) console.log('stream send. format:'+data.resoptions.format); if(data.streamingresponse==='audiocontent') { pcmplay.write(data.audiocontent); } else console.log('msg received:'+json.stringify(data)); kttts.on('end',()=>{ console.log('pcm end'); record.stop(); } else record.stop(); } else record.stop(); }; gpio.write(31,false); sysstat=0; } ktstt.write({reqoptions:{lang:0,usersession:'12345',deviceid:'d06190914tp808iqktzq'} let mic=initmic(); mic.on('data',(data)=>{ ktstt.write({audiocontent:data

130 const gpio=require('rpi-gpio'); const record=require('node-record-lpcm16'); const aikit=require('./aimakerskitutil'); const Speaker=require('speaker'); const fs=require('fs'); const soundbuffer=fs.readfilesync('../data/sample_sound.wav'); const pcmplay=new Speaker({ channels:1, bitdepth:16, samplerate:16000 gpio.setup(29,gpio.dir_in,gpio.edge_both); gpio.setup(31,gpio.dir_low,write);

131 let sysstat=0; gpio.on('change',(channel,value)=>{ if(channel===29){ console.log('channel:'+channel+' value is '+value); if(value===false){ if(sysstat===0) { sysstat=1; console.log('button Pressed. Start Service'); gpio.write(31,true); pcmplay.write(soundbuffer); settimeout(startqueryvoice,1000); } } }

132 }; gpio.write(31,false); sysstat=0; } ktstt.write({reqoptions:{lang:0,usersession:'12345',deviceid:'d06190914tp808iqktzq'} let mic=initmic(); mic.on('data',(data)=>{ ktstt.write({audiocontent:data

$ git clone https://github.com/hello-wade/amk_project_ example.git

134

135 Alternate Function Alternate Function 12C1 SDA 12C1 SCL SPIO MOSI SPIO MISO SPIO SCLK SPI1 MISO 3.3V PWR GPIO 2 GPIO 3 GPIO 4 GND GPIO 17 GPIO 27 GPIO 22 3.3V PWR GPIO 10 GPIO 9 GPIO 11 GND Reserved GPIO 5 GPIO 6 GPIO 13 GPIO 19 GPIO 26 GND 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 5V PWR 5V PWR GND UARTO TX UARTO TX GPIO 18 GND GPIO 23 GPIO 24 GND GPIO 25 GPIO 8 GPIO 7 Reserved GND GPIO 12 GND GPIO 16 GPIO 20 GPIO 21 SPIO CS0 SPIO CS1 SPI1 CS0 SPI1 MOSI SOI1 SCLK

136

137 const gpio = require('rpi-gpio'); const record = require('node-record-lpcm16'); const aikit = require('./aimakerskitutil'); const Speaker = require('speaker'); const fs = require('fs'); const soundbuffer = fs.readfilesync('../data/sample_sound.wav'); const pcmplay = new Speaker({ channels: 1, bitdepth: 16, samplerate: 16000 function initmic() { return record.start({ sampleratehertz: 16000, threshold: 0, verbose: false, recordprogram: 'arecord', }) }; const nodeversion = process.version.split('.')[0]; let ktkws=null; if(nodeversion === 'v6') ktkws = require('./ktkws'); else if(nodeversion === 'v8') ktkws = require('./ktkws_v8'); gpio.setup(31, gpio.dir_low, write); function write(err) { if(err) console.log('write Error:'+err); };

138 const json_path = '/home/pi/downloads/clientkey.json'; const cert_path = '../data/ca-bundle.pem'; const proto_path = '../data/gigagenierpc.proto'; const kwstext = ['','','','']; const kwsflag = parseint(process.argv[2]); ktkws.initialize('../data/kwsmodel.pack'); ktkws.startkws(kwsflag); let mic = initmic(); aikit.initializejson(json_path, cert_path, proto_path); let mode = 0; let ktstt = null; mic.on('data', (data) => { if(mode === 0) { result = ktkws.pushbuffer(data); if(result === 1) { console.log("kws Detected"); pcmplay.write(soundbuffer); settimeout(startstt, 1000); } } else { ktstt.write({audiocontent: data } console.log('say :' + kwstext[kwsflag]); function startstt() { ktstt = aikit.getvoice2text(); ktstt.on('error',(error) => { console.log('error:'+error);

139 ktstt.on('data', (data) => { console.log('stt result:' + JSON.stringify(data)); if (data.resultcd === 201) { controlled(data, function(result) { let responsestring = ""; if (result === 1) { responsestring = '.'; } else if (result === 2) { responsestring = '.'; } else { responsestring = '.'; } } playtts(responsestring, () => { mode = 0; if(data.resultcd!== 200 && data.resultcd!== 201) mode = 0; ktstt.on('end',() => { console.log('stt text stream end');

140 }; ktstt.write({reqoptions: {mode: 0, lang: 0} mode=1; function controlled (data, callback){ resulttext = data.recognizedtext; if (resulttext.search("") >= 0){ gpio.write(31, true); callback(1); } else if(resulttext.search("") >= 0){ gpio.write(31, false); callback(2); } } else { callback(0); }

141 function playtts (returnvoice, callback) { } kttts = aikit.gettext2voicestream({text: returnvoice, lang: 0, mode: 0 kttts.on('error', (error) => { console.log('error:'+error); kttts.on('data', (data) => { if (data.streamingresponse === 'resoptions' && data.resoptions.resultcd === 200){ console.log('stream send. format:'+data.resoptions.format); } if (data.streamingresponse ==='audiocontent') { pcmplay.write(data.audiocontent); } else { console.log('msg received:'+json.stringify(data)); } kttts.on('end', () => { console.log('pcm end'); settimeout(() => { console.log('tts played'); callback(); }, 800);

142

143

144 $ wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.50.tar.gz $ tar zxvf bcm2835-1.50.tar.gz $ cd bcm2835-1.50 $./configure $ make $ sudo make check $ sudo make install $ npm i node-dht-sensor

145 const record = require('node-record-lpcm16'); const aikit = require('./aimakerskitutil'); const Speaker = require('speaker'); var sensor = require('node-dht-sensor'); const fs = require('fs'); const soundbuffer = fs.readfilesync('../data/sample_sound.wav'); const pcmplay = new Speaker({ channels: 1, bitdepth: 16, samplerate: 16000 function initmic() { return record.start({ sampleratehertz: 16000, threshold: 0, verbose: false, recordprogram: 'arecord', }) }; const nodeversion = process.version.split('.')[0]; let ktkws=null; if(nodeversion === 'v6') ktkws = require('./ktkws'); else if(nodeversion === 'v8') ktkws = require('./ktkws_v8'); const json_path = '/home/pi/downloads/clientkey.json';

146 const cert_path = '../data/ca-bundle.pem'; const proto_path = '../data/gigagenierpc.proto'; const kwstext = ['','','','']; const kwsflag = parseint(process.argv[2]); ktkws.initialize('../data/kwsmodel.pack'); ktkws.startkws(kwsflag); let mic = initmic(); aikit.initializejson(json_path, cert_path, proto_path); let mode = 0; let ktstt = null; mic.on('data', (data) => { if(mode === 0) { result = ktkws.pushbuffer(data); if(result === 1) { console.log("kws Detected"); pcmplay.write(soundbuffer); settimeout(startstt, 1000); } } else { ktstt.write({audiocontent: data } console.log('say :' + kwstext[kwsflag]); function startstt() { ktstt = aikit.getvoice2text();

147 ktstt.on('error',(error) => { console.log('error:'+error); ktstt.on('data', (data) => { console.log('stt result:' + JSON.stringify(data)); if (data.resultcd === 201) { checkcommand(data, function(result) { let responsestring = ""; readsensor(11, 3, (err, temperature, humidity) => { } if(!err){ if (result === 1) { responsestring = '' + temperature + '.'; } else if (result === 2) { responsestring = '' + humidity + '.'; } else { responsestring = '.'; } playtts(responsestring, () => { mode = 0; } else{ console.log("") } if(data.resultcd!== 200 && data.resultcd!== 201) mode = 0;

148 }; ktstt.on('end',() => { console.log('stt text stream end'); ktstt.write({reqoptions: {mode: 0, lang: 0} mode=1; function checkcommand (data, callback){ resulttext = data.recognizedtext; if (resulttext.search("") >= 0){ callback(1); } else if(resulttext.search("") >= 0){ callback(2); } else { callback(0); } } function playtts (returnvoice, callback) { kttts = aikit.gettext2voicestream({text: returnvoice, lang: 0, mode: 0 kttts.on('error', (error) => { console.log('error:'+error); kttts.on('data', (data) => { if (data.streamingresponse === 'resoptions' && data.resoptions.resultcd === 200){ console.log('stream send. format:'+data.resoptions.format); }

149 if (data.streamingresponse ==='audiocontent') { pcmplay.write(data.audiocontent); } else { console.log('msg received:'+json.stringify(data)); } kttts.on('end', () => { console.log('pcm end'); settimeout(() => { console.log('tts played'); callback(); }, 800); } function readsensor(dht_ver, DHT_GPIO, callback) { sensor.read(dht_ver, DHT_GPIO, function(err, temperature, humidity) { if (!err) { console.log('temp: ' + temperature.tofixed(1) + ' C, ' + 'humidity: ' + humidity.tofixed(1) + '%' ); callback(err, temperature, humidity); } }

150 $ npm i youtube-audio-stream $ npm i fluent-ffmpeg $ sudo apt-get install ffmpeg

151 const record = require('node-record-lpcm16'); const aikit = require('./aimakerskitutil'); const fs = require('fs'); const Speaker = require('speaker'); let ktkws = null; const nodeversion = process.version.split('.')[0]; if(nodeversion === 'v6') ktkws = require('./ktkws'); else if(nodeversion === 'v8') ktkws = require('./ktkws_v8'); const request = require('request'); const json_path = '/home/pi/downloads/clientkey.json'; const cert_path = '../data/ca-bundle.pem'; const proto_path = '../data/gigagenierpc.proto'; const kwstext = ['', '', '', '']; const kwsflag = parseint(process.argv[2]); const soundbuffer = fs.readfilesync('../data/sample_sound.wav'); const pcmplay = new Speaker({ channels: 1, bitdepth: 16, samplerate: 16000 function initmic() { return record.start({ sampleratehertz: 16000, threshold: 0, verbose: false, recordprogram: 'arecord' };

152 ktkws.initialize('../data/kwsmodel.pack'); ktkws.startkws(kwsflag); let mic = initmic(); aikit.initializejson(json_path, cert_path, proto_path); let mode = 0; // 0 : kws, 1 : stt let ktstt = null; let player = null; mic.on('data', (data) => { if(mode === 0) { result = ktkws.pushbuffer(data); if(result === 1) { console.log("kws Detected"); pcmplay.write(soundbuffer); settimeout(startstt, 1000); } } else { ktstt.write({audiocontent: data if(player!= null) { player.stop(); } } function starttts(text, speaker) { let kttts = aikit.gettext2voicestream({text: text, lang: 0, mode: 0 kttts.on('error', (error) => console.log('error:' + error)); kttts.on('data', (data) => { if (data.streamingresponse === 'resoptions' && data.resoptions.resultcd === 200) { console.log('stream send. format:' + data.resoptions.format); }

153 } if (data.streamingresponse === 'audiocontent') { speaker.write(data.audiocontent); } else { console.log('msg received:' + JSON.stringify(data)); } kttts.on('end', () => console.log('pcm end')); console.log('say :' + kwstext[kwsflag]); function startstt() { ktstt = aikit.getvoice2text(); ktstt.on('error', (error) => console.log('error:' + error)); ktstt.on('data', async (data) => { console.log('stt result:' + JSON.stringify(data)); if (data.resultcd === 201) { const recognizedtext = data.recognizedtext; if (recognizedtext.includes('') && (recognizedtext.includes('') recognizedtext.includes(''))) { let target = recognizedtext.split('')[0]; console.log('play Target:' + target); const ttscomment = ' ' + target + ' '; starttts(ttscomment, pcmplay); player = new YoutubePlayer(await getyoutubeurl(target), pcmplay); player.play();

154 } else if(recognizedtext.includes('')) { if (player!= null) { player.stop(); player = null; const ttscomment = '.'; starttts(ttscomment, pcmplay); } } else { if (player!= null) { player.play(); } } mode = 0; } ktstt.on('end', () => { console.log('stt text stream end'); mode = 0; ktstt.write({reqoptions: {mode: 0, lang: 0} mode = 1; };

155 async function getyoutubeurl(keyword) { const youtubeplaybaseurl = 'https://www.youtube.com/watch?'; let urls = await getyoutubesearchlist(keyword); let targeturl = youtubeplaybaseurl + urls[0]; console.log('yt url:' + targeturl); } return targeturl; function getyoutubesearchlist(target) { const querytext = target; } return new Promise((resolve, reject) => { console.log('querytext: ' + querytext); const searchurl = 'https://www.youtube.com/results?search_query='; const queryurl = encodeuri(searchurl + querytext); request(queryurl, (err, res, body) => { let splitbywatch = body.split('href=\"\/watch?'); let isfirst = true; let urllist = []; splitbywatch.foreach((splittext) => { if (isfirst === true) { isfirst = false; } else { let splitbyquot = splittext.split('"'); urllist.push(splitbyquot[0]); } resolve(urllist);

156 const getyoutubestream = require('youtube-audio-stream'); const ffmpeg = require('fluent-ffmpeg'); class YoutubePlayer { constructor(url, speaker) { this.url = url; this.status = 'stop'; this.stream = this._initstream(); this.speaker = speaker; } _initstream() { var ffstream = ffmpeg({source: getyoutubestream(this.url)}).inputformat('mp3').format('wav').outputoptions([ '-b:a 332k', '-ar 16000', '-ab 64', '-ac 1', ]).pipe(); } return ffstream;

157 } play () { if(this.status === 'stop') { this.stream.pipe(this.speaker); this.status = 'play'; } } stop () { if(this.status === 'play') { this.stream.unpipe(); this.status = 'stop'; } }

(sleep 10 && cd ~/ai-makers-kit/nodejs && node ex9_btnsttdss.js)& $ nano.profile