• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstdio>
17 #include <iostream>
18 #include <memory>
19 
20 #include "kws_manager.h"
21 
22 using namespace std;
23 using namespace KWS;
24 
SampleHelp()25 static void SampleHelp()
26 {
27     printf("****************************************\n");
28     printf("Select the behavior of KWS app.\n");
29     printf("s: AudioCap (Press q to quit)\n");
30     printf("q: quit the sample.\n");
31     printf("****************************************\n");
32 }
33 
main()34 int main()
35 {
36     printf("Keyword spotting started.\n");
37     SampleHelp();
38 
39     shared_ptr<KwsManager> kwsMgr = make_shared<KwsManager>(AUDIO_SAMPLE_RATE, AUDIO_CODEC_BITRATE);
40     if (kwsMgr == nullptr) {
41         printf("Keyword spotting failed to allocate KWSManager.\n");
42         return -1;
43     }
44     if (!kwsMgr->Prepare()) {
45         printf("Keyword spotting failed to prepare KWSManager.\n");
46         return -1;
47     }
48     char input = ' ';
49     while (cin >> input) {
50         switch (input) {
51             case 's':
52                 kwsMgr->Start();
53                 break;
54             case 'q':
55                 kwsMgr->Stop();
56                 printf("Keyword spotting Terminated.\n");
57                 return 0;
58             default:
59                 SampleHelp();
60                 break;
61         }
62     }
63     return 0;
64 }