9 #if defined(_WIN32) || defined(WIN32)
39 std::string
GetEnv(
const std::string& name)
41 char *data=getenv(name.c_str());
43 return std::string(data);
50 bool stopthread=
false;
52 #if defined(_WIN32) || defined(WIN32)
54 _setmode(_fileno(stdin), _O_BINARY);
55 _setmode(_fileno(stdout), _O_BINARY);
63 std::cerr <<
"ProcessLoop: input stopped"<< std::endl;
67 if (stopthread)
break;
72 std::cerr <<
"Failed to write audio output" << std::endl;
79 void Usage(
const char *progname)
81 std::cerr <<
"Usage: " << progname << std::endl;;
82 std::cerr <<
" Reads audio from stdin and return processed audio in stdout" << std::endl;
83 std::cerr <<
"Environment:"<< std::endl;;
84 std::cerr <<
" - S4STORE_PATH : path to store config [default: (no storage)]"<< std::endl;;
85 std::cerr <<
" - S4LOGINKEY : SOUND4 Login key (or S4USERID)"<< std::endl;;
86 std::cerr <<
" - RADIO_NAME : SOUND4 Radio Name"<< std::endl;;
87 std::cerr <<
" - ACCESS_KEY_ID : SOUND4 Access Key ID"<< std::endl;;
88 std::cerr <<
" - ACCESS_KEY_SECRET : SOUND4 Access Key Secret"<< std::endl;;
89 std::cerr << std::endl;
90 std::cerr <<
"Example:"<< std::endl;
91 std::cerr <<
"ffmpeg -re -i file.wav -ar "<<sound4::bigvoice::GetSampleRate()<<
" -ac "<<sound4::bigvoice::GetChannelCount()<<
" -f f32le - | "<<progname<<
" | ffplay -f f32le -ar "<<sound4::bigvoice::GetSampleRate()<<
" -ac "<<sound4::bigvoice::GetChannelCount()<<
" -i -" << std::endl;;
92 #if defined(_WIN32) || defined(WIN32)
93 std::cerr <<
"ffmpeg -f dshow -i audio=\"Microphone\" -ar "<<sound4::bigvoice::GetSampleRate()<<
" -ac "<<sound4::bigvoice::GetChannelCount()<<
" -f f32le - | "<<progname<<
" | ffplay -f f32le -ar "<<sound4::bigvoice::GetSampleRate()<<
" -ac "<<sound4::bigvoice::GetChannelCount()<<
" -i -" << std::endl;;
95 std::cerr <<
"ffmpeg -f pulse -i default -ar "<<sound4::bigvoice::GetSampleRate()<<
" -ac "<<sound4::bigvoice::GetChannelCount()<<
" -f f32le - | "<<progname<<
" | ffplay -f f32le -ar "<<sound4::bigvoice::GetSampleRate()<<
" -ac "<<sound4::bigvoice::GetChannelCount()<<
" -i -" << std::endl;;
101 std::cerr << msg << std::endl;
104 int main(
int argc,
const char **argv)
106 #if (BIGVOICE_HAS_WEBSERVER)
107 int listen_port = 8080;
109 auto store_path_str=
GetEnv(
"S4STORE_PATH");
112 auto LoginKey=
GetEnv(
"S4LOGINKEY");
113 if (LoginKey.empty()) {
114 LoginKey=
GetEnv(
"S4USERID");
116 auto RadioName=
GetEnv(
"RADIO_NAME");
117 auto KeyId=
GetEnv(
"ACCESS_KEY_ID");
118 auto AccessKey=
GetEnv(
"ACCESS_KEY_SECRET");
120 const char *progname=argv[0];
123 if ((strcasecmp(argv[1],
"-h")==0) || (strcasecmp(argv[1],
"--help")==0)) {
128 if (LoginKey.empty() || RadioName.empty() || KeyId.empty() || AccessKey.empty()) {
129 std::cerr <<
"Missing credentials in environment" << std::endl;
133 std::filesystem::path store_path;
134 if (!store_path_str.empty()) {
135 store_path = std::filesystem::path(store_path_str);
136 if (!std::filesystem::exists(store_path) || !std::filesystem::is_directory(store_path)) {
137 std::cerr <<
"Storage folder '"<<store_path.c_str()<<
"' is not a valid directory" << std::endl;
144 sound4::bigvoice::SetLogSeverity(
verbose5);
145 sound4::bigvoice::SetLoggerCallback(
MyLogger);
148 instance.
SetParam(
"ADMIN_USER",
"admin");
149 instance.
SetParam(
"ADMIN_SECRET",
"admin");
152 std::cerr <<
"Creating" << std::endl;
154 if (!instance.
Create(LoginKey, RadioName, KeyId, AccessKey, store_path)) {
155 std::cerr <<
"Failed to create the processing instance" << std::endl;
160 #if (BIGVOICE_HAS_WEBSERVER)
161 std::cerr <<
"Starting web server" << std::endl;
164 std::cerr <<
"Failed to create the web server on port " << listen_port << std::endl;
173 auto answer = client->ProcessJson(R
"JSON({"get":{"processorname":null}})JSON");
174 std::cerr << "Request for processor name returned "<<answer<<std::endl;
180 std::cerr <<
"Stopping now" << std::endl;
183 std::cerr <<
"End" << std::endl;
std::array< float, OutputSampleSize > & GetBufferOut()
std::array< float, InputSampleSize > & GetBufferIn()
std::shared_ptr< CClient > NewClient()
bool StartWebServer(int http_port, int https_port=0)
bool Create(const std::string &LoginKey, const std::string &RadioName, const std::string &AWS_Access_ID, const std::string &AWS_Access_Secret, const std::filesystem::path &save_path, int json_port=0, unsigned int frames_per_chunk=12)
void SetParam(const std::string &name, const std::string &value)
const size_t OutputSampleSize
const size_t InputSampleSize
int main(int argc, const char **argv)
void MyLogger(sound4::bigvoice::LogSeverity severity, const std::string &msg)
std::string GetEnv(const std::string &name)
void ProcessLoop(sound4::bigvoice::CInstance &instance)
void Usage(const char *progname)