-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServiceStt.cpp
88 lines (78 loc) · 1.54 KB
/
ServiceStt.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "stdafx.h"
#include "ServiceStt.h"
void SttThread::set_STT(STT_NEOP * stt)
{
this->stt = stt;
}
void SttThread::Start()
{
this->start = TRUE;
}
void SttThread::Stop()
{
this->start = FALSE;
}
void SttThread::setDevice(std::string deviceName)
{
this->deviceName = deviceName;
input->setDevice(deviceName);
}
void SttThread::run()
{
t1=new std::thread(&SttThread::Process, this);
}
void SttThread::Process()
{
if (!sf::SoundRecorder::isAvailable())
{
MessageBox(
NULL,
(LPCWSTR)L"No recording device is detect",
(LPCWSTR)L"STT Details",
MB_CANCELTRYCONTINUE
);
}
else {
input = new PlaybackRecorder();
input->setChannelCount(1);
lock.lock();
while (true)
{
while (start)
{
input->start(16000);
while (!input->isSilent())
{
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
input->initNbSilence();
input->stop();
const sf::SoundBuffer & soundBf = input->getBuffer();
ch = "audio" + std::to_string(i) + ".wav";
soundBf.saveToFile(ch);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
setAudio((char *)ch.c_str());
services.push_back(std::thread(&STT_NEOP::multiProcess, stt, 0));
i++;
}
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
lock.unlock();
}
}
const std::string & SttThread::getDevice() const
{
return input->getDevice();
}
void SttThread::setAudio(char* audioFile)
{
this->stt->setAudio(audioFile);
}
BOOL SttThread::isRunning()
{
return this->start;
}
SttThread::~SttThread()
{
t1->join();
}