Exemplo n.º 1
0
int main() {
	cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!

	FileStream fileStream = File.OpenRead("recorded.flac");//my.flac
	MemoryStream memoryStream = new MemoryStream();
	memoryStream.SetLength(fileStream.Length);
	fileStream.Read(memoryStream.GetBuffer(), 0, (int)fileStream.Length);
	byte[] BA_AudioFile = memoryStream.GetBuffer();
	HttpWebRequest _HWR_SpeechToText = null;
	_HWR_SpeechToText = (HttpWebRequest)HttpWebRequest.Create("https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=" + ACCESS_GOOGLE_SPEECH_KEY);
	_HWR_SpeechToText.Credentials = CredentialCache.DefaultCredentials;
	_HWR_SpeechToText.Method = "POST";
	_HWR_SpeechToText.ContentType = "audio/x-flac; rate=44100";
	_HWR_SpeechToText.ContentLength = BA_AudioFile.Length;
	Stream stream = _HWR_SpeechToText.GetRequestStream();
	stream.Write(BA_AudioFile, 0, BA_AudioFile.Length);
	stream.Close();
	HttpWebResponse HWR_Response = (HttpWebResponse)_HWR_SpeechToText.GetResponse();

	StreamReader SR_Response = new StreamReader(HWR_Response.GetResponseStream());
	string responseFromServer = (SR_Response.ReadToEnd());

	String[] jsons = responseFromServer.Split('\n');
	foreach (String j in jsons)
	{
		dynamic jsonObject = JsonConvert.DeserializeObject(j);
		if (jsonObject == null || jsonObject.result.Count <= 0)
		{
			continue;
		}
		text = jsonObject.result[0].alternative[0].transcript;
		jsons = null;
	}
Exemplo n.º 2
0
void DeleteStaleSaveGames()
{
	for (int nGame = knGameReinitializeSave; nGame < 20;) {
		Stream *pstm = HostOpenSaveGameStream(nGame, false);
		if (pstm != NULL) {
			char szVersion[32];
			szVersion[0] = 0;
			pstm->ReadString(szVersion, sizeof(szVersion));
			byte bVer = pstm->ReadByte();
			byte bPlatform = 0;
			if (bVer >= 6)
				bPlatform = pstm->ReadByte();
			pstm->Close();
			delete pstm;

			if (!CheckSaveGameVersion(szVersion, bPlatform))
				HostDeleteSaveGame(NULL, nGame);
		}

		// Ugly

		if (nGame == knGameReinitializeSave) {
			nGame = 0;
		} else {
			nGame++;
		}
	}

	// delete any crashed save games

	HostDeleteSaveGame(kszTempName, 0);
}
Exemplo n.º 3
0
void TEST_Serialization::LeafJoins()
{
	ObjectFactory<Serializable> factory;
	factory.Register("ObjectA", new ObjectCreator<ObjectA, Serializable>());
	factory.Register("ObjectC", new ObjectCreator<ObjectC, Serializable>());

	Stream * file = new BinaryFileStream();
	file->StartWrite("test9.txt");

	ObjectA * a = new ObjectA(1, 2, 3);
	ObjectC * c = new ObjectC(4, 5, 6, a);
	ObjectC * c2 = new ObjectC(7, 8, 9, a);

	*file << c;
	*file << c2;
	*file << a;

	file->Close();

	file->StartRead("test9.txt", factory);
	
	ObjectC * load_c;
	ObjectC * load_c2;
	ObjectA * load_a;
	file->Load(load_c);
	file->Load(load_c2);
	file->Load(load_a);

	load_c->a->Print();
	load_c2->a->Print();

	load_a->Set(12, 12, 12);

	load_c->a->Print();
	load_c2->a->Print();


	file->Close();
	delete file;
	delete c;
	delete c2;
	delete a;
	delete load_c;
	delete load_c2;
	delete load_a;
}
Exemplo n.º 4
0
bool SaveStreamBOM(Stream& out, const WString& data) {
	if(!out.IsOpen() || out.IsError()) 
		return false;
	word w = 0xfeff;
	out.Put(&w, 2);
	out.Put(~data, 2 * data.GetLength());
	out.Close();
	return out.IsOK();
}
Exemplo n.º 5
0
bool SaveStreamBOMUtf8(Stream& out, const String& data) {
	if(!out.IsOpen() || out.IsError()) 
		return false;
	static unsigned char bom[] = {0xEF, 0xBB, 0xBF};
	out.Put(bom, 3);
	out.Put(ToCharset(CHARSET_UTF8, data));
	out.Close();
	return out.IsOK();
}
Exemplo n.º 6
0
int Stream::SetFailed(StreamId id) {
    SocketUniquePtr ptr;
    if (Socket::AddressFailedAsWell(id, &ptr) == -1) {
        // Don't care recycled stream
        return 0;
    }
    Stream* s = (Stream*)ptr->conn();
    s->Close();
    return 0;
}
Exemplo n.º 7
0
void TEST_Serialization::Inheritance()
{
	ObjectFactory<Serializable> factory;
	factory.Register("ObjectB", new ObjectCreator<ObjectB, Serializable>());

	Stream * file = new BinaryFileStream();
	file->StartWrite("test8.txt");

	ObjectB * b = new ObjectB(1, 2, 3, 1337);

	*file << b;

	file->Close();

	file->StartRead("test8.txt", factory);
	
	ObjectB * load_b;
	file->Load(load_b);

	file->Close();
	delete file;
	delete b;
	delete load_b;
}
Exemplo n.º 8
0
bool Stream::ReadToStream(Environment &env, Stream &streamDst,
			size_t bytesUnit, bool finalizeFlag, const Function *pFuncFilter)
{
	Signal &sig = env.GetSignal();
	if (!CheckReadable(sig) || !streamDst.CheckWritable(sig)) return false;
	Attribute attr;
	bool validAttrFlag = false;
	if (finalizeFlag) {
		validAttrFlag = GetAttribute(attr);
	}
	AutoPtr<Memory> pMemory(new MemoryHeap(bytesUnit));
	char *buff = reinterpret_cast<char *>(pMemory->GetPointer());
	for (;;) {
		size_t bytesRead = Read(sig, buff, bytesUnit);
		if (bytesRead == 0) break;
		if (pFuncFilter != nullptr) {
			Value value(new Object_binary(env, buff, bytesUnit, false));
			AutoPtr<Argument> pArgSub(new Argument(pFuncFilter));
			if (!pArgSub->StoreValue(env, value)) return false;
			Value rtn = pFuncFilter->Eval(env, *pArgSub);
			if (sig.IsSignalled()) return false;
			if (rtn.Is_binary()) {
				const Binary &buffRtn = rtn.GetBinary();
				streamDst.Write(sig, buffRtn.data(), buffRtn.size());
				if (sig.IsSignalled()) return false;
				continue;
			}
		}
		streamDst.Write(sig, buff, bytesRead);
		if (sig.IsSignalled()) return false;
	}
	if (sig.IsSignalled()) return false;
	if (finalizeFlag) {
		streamDst.Close();
		if (sig.IsSignalled()) return false;
		if (validAttrFlag) streamDst.SetAttribute(attr);
		return true;
	}
	if (!streamDst.Flush(sig)) return false;
	return true;
}
void ResourceCompiler::Update_File_Timestamp(std::string path)
{
	Platform* platform = Platform::Get();
	
	std::string input_directory	= platform->Extract_Directory(path);
	std::string input_filename	= platform->Extract_Filename(path);
	std::string output_directory= Directory_To_Output_Directory(input_directory);
	std::string output_path		= platform->Join_Path(output_directory, input_filename + ".timestamp");	
	u64			input_timestamp = StreamFactory::Get_Last_Modified(path.c_str());

	Stream* stream = StreamFactory::Open(output_path.c_str(), StreamMode::Write);
	if (stream == NULL)
	{
		return;
	}

	stream->WriteInt32(input_timestamp);
	stream->Close();

	SAFE_DELETE(stream);
}
Exemplo n.º 10
0
void TEST_Serialization::SimpleSaveLoad()
{

	ObjectFactory<Serializable> factory;
	factory.Register("ObjectA", new ObjectCreator<ObjectA, Serializable>());

	
	ObjectA * save_pointer = new ObjectA(3, 4, 5);
	int save_int = 5;
	float save_float = 3.5f;
	double save_double = 3.5;
	char save_char = '5';
	bool save_bool = true;
	short save_short = 7;
	long save_long = 67;
	long double save_longdouble = 254.344;
	const char * save_string = "wee";
	unsigned int save_uint = 34;
	unsigned char save_uchar = '3';
	unsigned short save_ushort = 232;
	unsigned long save_ulong = 34 ;
	ObjectA save_object = ObjectA(6, 7, 8);

	ObjectA * load_pointer;
	int load_int = 0;
	float load_float = 0;
	double load_double = 0;
	char load_char = 0;
	bool load_bool = 0;
	short load_short = 0;
	long load_long = 0;
	long double load_longdouble = 0;
	char * load_string = 0;
	unsigned int load_uint = 0;
	unsigned char load_uchar = 0;
	unsigned short load_ushort = 0;
	unsigned long load_ulong = 0;
	ObjectA load_object;
	

	Stream  * file = new BinaryFileStream();
	file->StartWrite("test6.txt");

	file->Save(save_pointer);
	file->Save(save_int);
	file->Save(save_float);
	file->Save(save_double);
	file->Save(save_char);
	file->Save(save_bool);
	file->Save(save_short);
	file->Save(save_long);
	file->Save(save_longdouble);
	file->Save(save_string);
	file->Save(save_uint);
	file->Save(save_uchar);
	file->Save(save_ushort);
	file->Save(save_ulong);
	file->Save(save_object);

	file->Close();

	file->StartRead("test6.txt", factory);
	
	file->Load(load_pointer);
	file->Load(load_int);
	file->Load(load_float);
	file->Load(load_double);
	file->Load(load_char);
	file->Load(load_bool);
	file->Load(load_short);
	file->Load(load_long);
	file->Load(load_longdouble);
	file->Load(load_string);
	file->Load(load_uint);
	file->Load(load_uchar);
	file->Load(load_ushort);
	file->Load(load_ulong);
	file->Load(load_object);

	file->Close();
	delete file;
	
	Assert(save_int == load_int, "int equal");
	Assert(save_float == load_float, "float not equal");
	Assert(save_double == load_double, "double not equal");
	Assert(save_char == load_char, "char not equal");
	Assert(save_bool == load_bool, "bool not equal");
	Assert(save_short == load_short, "short not equal");
	Assert(save_long == load_long, "long not equal");
	Assert(save_longdouble == load_longdouble, "long not equal");
	Assert(strcmp(save_string, load_string) == 0, "strings not equal");
	Assert(save_uint == load_uint, "uint not equal");
	Assert(save_uchar == load_uchar, "uchar not equal");
	Assert(save_ushort == load_ushort, "ushort not equal");
	Assert(save_ulong == load_ulong, "ulong not equal");

	delete save_pointer;
	delete load_pointer;
	delete load_string;
}
Exemplo n.º 11
0
void TEST_Serialization::SimpleSaveLoad1D()
{
	ObjectFactory<Serializable> factory;
	factory.Register("ObjectA", new ObjectCreator<ObjectA, Serializable>());


	ObjectA * save_pointer = new ObjectA();
	save_pointer->Set(1, 2, 3);
	int * save_int = new int[3];
	float * save_float = new float[3];
	double * save_double = new double[3];
	char * save_char = new char[3];
	bool * save_bool = new bool[3];
	short * save_short = new short[3];
	long * save_long = new long[3];
	long double * save_longdouble = new long double[3];
	unsigned int * save_uint = new unsigned int[3];
	unsigned char * save_uchar = new unsigned char[3];
	unsigned short * save_ushort = new unsigned short[3];
	unsigned long * save_ulong = new unsigned long[3];
	

	ObjectA * load_pointer = 0;
	int * load_int = 0;
	float * load_float = 0;
	double * load_double = 0;
	char * load_char = 0;
	bool * load_bool = 0;
	short * load_short = 0;
	long * load_long = 0;
	long double * load_longdouble = 0;
	unsigned int * load_uint = 0;
	unsigned char * load_uchar = 0;
	unsigned short * load_ushort = 0;
	unsigned long * load_ulong = 0;
	

	Stream  * file = new BinaryFileStream();
	file->StartWrite("test7.txt");

	file->Save(save_pointer);
	file->Save(save_int, 3);
	file->Save(save_float, 3);
	file->Save(save_double, 3);
	file->Save(save_char, 3);
	file->Save(save_bool, 3);
	file->Save(save_short, 3);
	file->Save(save_long, 3);
	file->Save(save_longdouble, 3);
	file->Save(save_uint, 3);
	file->Save(save_uchar, 3);
	file->Save(save_ushort, 3);
	file->Save(save_ulong, 3);
	

	file->Close();

	file->StartRead("test7.txt", factory);
	
	file->Load(load_pointer);
	file->Load(load_int);
	file->Load(load_float);
	file->Load(load_double);
	file->Load(load_char);
	file->Load(load_bool);
	file->Load(load_short);
	file->Load(load_long);
	file->Load(load_longdouble);
	file->Load(load_uint);
	file->Load(load_uchar);
	file->Load(load_ushort);
	file->Load(load_ulong);
	


	file->Close();
	delete file;


	delete save_pointer;
	delete [] save_int;
	delete [] save_float;
	delete [] save_double;
	delete [] save_char;
	delete [] save_bool;
	delete [] save_short;
	delete [] save_long;
	delete [] save_longdouble;
	delete [] save_uint;
	delete [] save_uchar;
	delete [] save_ushort;
	delete [] save_ulong;
	

	delete load_pointer;
	delete [] load_int;
	delete [] load_float;
	delete [] load_double;
	delete [] load_char;
	delete [] load_bool;
	delete [] load_short;
	delete [] load_long;
	delete [] load_longdouble;
	delete [] load_uint;
	delete [] load_uchar;
	delete [] load_ushort;
	delete [] load_ulong;
	
}
Exemplo n.º 12
0
void DockBase::SerializeLayout(Stream& s, bool deflay)
{
	CtrlRecord* record	= NULL;
	DockableCtrl* ctrl	= NULL;
	TreeCtrl& tree		= grouptab.grouptree;	
	String  name;
	int		panesize	= 0;
	int 	type 		= 0;
	int 	alignment	= 0;
	int 	state		= 0;
	int 	position	= 0;
	int 	id			= 0;
	int 	childcount	= 0;
	Size	childsize;
	
		if(s.IsStoring())
		{
			// Remove unused TabWindows (BugFix).
			RefreshTabWindowList();
			// Write Tabbing mode.
			s % tabsnested;
			// Write Widgets.
			// Write Docked (shown or hidden) and AutoHidden widgets.
			childcount = GetDockedWindowCount();
			s / childcount;
			if(childcount)
				for(int i = 0; i < childcount; i++)
				{
					ctrl = GetDockedWindowFromIndex(i);
					ASSERT(ctrl);
					ctrl->Serialize(s);
				}
			// Write PaneFrame sizes.
			for(int i = 0; i < 4; i++)  
			{
				panesize = GetPaneFrame(i).GetSize();
				s / panesize;
			}
			childcount = 0;
			int ctrlscount = ctrls.GetCount();
			// Write Floating Dockwindows.
			for(int i = 0; i < ctrlscount * 2; i++)
			{
				if(i < ctrlscount) childcount += GetCtrlRecordFromIndex(i)->ctrl->IsFloating() ? 1 : 0;
				if(i >= ctrlscount) 
				{
					if(i == ctrlscount) s / childcount;
					ctrl = GetCtrlRecordFromIndex(i - ctrlscount)->ctrl;
					ASSERT(ctrl);
					if(ctrl->IsFloating()) ctrl->Serialize(s);
				}
			}
			childcount = 0;
			// Write Floating TabWindows.
			int tabwindowcount = GetTabWindowCount();
			if(tabwindowcount)
				for(int i = 0; i < tabwindowcount * 2; i++)
				{
					if(i <  tabwindowcount) childcount += GetTabWindowFromIndex(i)->IsFloating() ? 1 : 0;
					if(i >= tabwindowcount)
					{
						if(i == tabwindowcount) s / childcount;
						TabWindow* tabwindow = GetTabWindowFromIndex(i - tabwindowcount);
						ASSERT(tabwindow);
						if(tabwindow->IsFloating()) tabwindow->Serialize(s);
					}
				}
		}

		if(s.IsLoading())
		{
			childcount = 0;
			// Close All widgets.
			for(int i = 0; i < GetTabWindowCount(); i++)	GetTabWindowFromIndex(i)->DetachAll();
			for(int i = 0; i < ctrls.GetCount(); i++) 		GetCtrlRecordFromIndex(i)->ctrl->Shut();
			// Remove unused TabWindows (BugFix).
			RefreshTabWindowList();
			// Read Tabbing Mode
			s % tabsnested;
			controlpanel.TabOptionNest <<= tabsnested;
			// Read Docked (shown or hidden) and AutoHidden widgets.
			s / childcount;
			if(childcount)
				for(int i = 0; i < childcount; i++)
				{
					s / type / id;
					if(type == DockableCtrl::TYPE_DOCKWINDOW)
						GetCtrlRecordFromId(id)->ctrl->Serialize(s);
					if(type == DockableCtrl::TYPE_TABWINDOW)
						GetPaneFrame(0).AddTabWindow()->Serialize(s);
				}
			// Read PaneFrame sizes.
			for(int i = 0; i < 4; i++)
			{
				s / panesize;
				GetPaneFrame(i).SetSize(panesize);
			}
			childcount = 0;
			s / childcount;
			if(childcount)
				for(int i = 0; i < childcount; i++)
				{
					s / type / id;
					GetCtrlRecordFromId(id)->ctrl->Serialize(s);
				}
			
			childcount = 0;
			s / childcount;
			if(childcount)
				for(int j = 0; j < childcount; j++)
				{
					s / type / id;
					TabWindow* tabwindow = GetPaneFrame(0).AddTabWindow();
					tabwindow->Serialize(s);
				}
		}		
		s.Close();
}