Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //----------------------------------------------//
- // Speech Time v 2.1 //
- // //
- // [email protected] //
- // //
- // Licence: GNU/GPL //
- // //
- //----------------------------------------------//
- // main.cpp
- #include <iostream> //Kniznica pre IO operacie
- #include <string> //Kniznica pre pracu s string retazcami
- #include <windows.h> //Kniznica pre skrytie windows okna
- #include "Speech.h"
- using namespace std;
- const char STR_CONSOLE_WINDOW_CLASS[] = "ConsoleWindowClass";
- void HideConsole();
- int main()
- {
- HideConsole();
- bool hod,pol_hod,mod[4];
- string config,home,cesta,p_cesta,a_cesta,jazyk;
- int Hlasitost,Hodina,Ton;
- // Nastavenie ciest pre config
- //cesta = "/SpeechTime/"; // Linux cesta s ulozenym config file
- //home = getenv("HOME"); // Linux home adresar
- cesta = "\\Program Files\\SpeechTime\\"; // Windows cesta s ulozenym config file
- home = getenv("SYSTEMDRIVE"); // Windows home jednotka
- p_cesta = home + cesta;
- string name_audio[32] = {"0.wav","1.wav","2.wav","3.wav","4.wav","5.wav","6.wav","7.wav","8.wav","9.wav","10.wav","11.wav",
- "12.wav","13.wav","14.wav","15.wav","16.wav","17.wav","18.wav","19.wav","20.wav","21.wav","22.wav",
- "23.wav","24.wav","25.wav","26.wav","27.wav","28.wav","29.wav","30.wav","31.wav"};
- Speech R_Cas(&name_audio[0]);
- // oznamenie datumu
- int *datum = new int;
- config = p_cesta + "date"; // vytvorenie absolutnej cesty pre config hlasitosti
- if (!(R_Cas.Read_Config(*datum, config.c_str()))) // Nacitanie configu ci sa ma alebo nema oznamit datum
- *datum = 1;
- if (*datum == 1)
- {
- sf::Sleep(60); // Casove oneskorenie pre nacitanie OS a pod
- // nacitanie config pre volume
- config = p_cesta + "volume"; // vytvorenie absolutnej cesty pre config hlasitosti
- if (!(R_Cas.Read_Config(Hlasitost, config.c_str()))) // Nacitanie hlasitosti
- Hlasitost = 100;
- // nacitanie config pre jazyk
- config = p_cesta + "language"; // Vytvorenie absolutnej cesty pre config jazyka
- if (!(R_Cas.Language(jazyk, config.c_str()))) // nacitanie jazyka
- jazyk = "EN";
- string cesta_den,cesta_mesiac,cesta_den_tyzdni;
- int den,mesiac,dent;
- R_Cas.Read_Date(dent,den,mesiac);
- //cesta_den_tyzdni = p_cesta + "Audio/" + jazyk + "/" + "Date/dayt/" + name_audio[dent]; // Linux
- cesta_den_tyzdni = p_cesta + "Audio\\" + jazyk + "\\Date\\dayt\\" + name_audio[dent]; // Windows
- //cesta_den = p_cesta + "Audio/" + jazyk + "/" + "Date/day/" + name_audio[den]; // Linux
- cesta_den = p_cesta + "Audio\\" + jazyk + "\\Date\\day\\" + name_audio[den]; // Windows
- //cesta_mesiac = p_cesta + "Audio/" + jazyk + "/" + "Date/moon/" + name_audio[mesiac]; // Linux
- cesta_mesiac = p_cesta + "Audio\\" + jazyk + "\\Date\\moon\\" + name_audio[mesiac]; // Windows
- R_Cas.Play_date(Hlasitost,cesta_den_tyzdni,cesta_den,cesta_mesiac);
- }
- delete datum;
- // kontrola casu a samotne prehratie
- for (;;)
- {
- sf::Sleep(0.1);
- // nacitanie config pre volume
- config = p_cesta + "volume"; // vytvorenie absolutnej cesty pre config hlasitosti
- if (!(R_Cas.Read_Config(Hlasitost, config.c_str()))) // Nacitanie hlasitosti
- Hlasitost = 100;
- // nacitanie config pre mod prehravania
- config = p_cesta + "config"; // Vytvorenie absolutnej cesty pre config modu prehravania
- if (!(R_Cas.Read_set_play(mod, config.c_str()))) // nacitanie modu prehravania
- mod = {1,0,1,0};
- // nacitanie tonu prehravania
- config = p_cesta + "ton"; // Vytvorenie absolutnej cesty pre ton
- if (!(R_Cas.Read_Config(Ton, config.c_str()))) // Precitanie nastavenia tonu
- Ton = 1;
- // nacitanie config pre jazyk
- config = p_cesta + "language"; // Vytvorenie absolutnej cesty pre config jazyka
- if (!(R_Cas.Language(jazyk, config.c_str()))) // nacitanie jazyka
- jazyk = "EN";
- if (R_Cas.Control_time(hod,pol_hod,Hodina)) // kontrola casu (celej hodiny a pol hodiny )
- {
- //a_cesta = p_cesta + "Audio/Tone/"; // Linux
- a_cesta = p_cesta + "Audio\\Tone\\"; // Windows
- R_Cas.Play_ton(hod,pol_hod,mod,Hlasitost,Ton,a_cesta); // prehravanie tonu
- sf::Sleep(0.40); // casove oneskorenie medzi prehravanim
- //a_cesta = p_cesta + "Audio/" + jazyk + "/" + "Time/"; // Linux
- a_cesta = p_cesta + "Audio\\" + jazyk + "\\Time\\"; // Windows
- R_Cas.Play_time(hod,pol_hod,mod,Hlasitost,Hodina,jazyk,a_cesta); // prehravanie audio stop
- sf::Sleep(60); // casove oneskorenie aby sa stale dookola neprehravalo... Moze sa stat ze za minutu stihne prehrat aj 2 krat
- }
- }
- }
- std::string GetConsoleTitle()
- {
- unsigned long length;
- std::string result( 1000, '\0' );
- length = GetConsoleTitle(const_cast<char *>(result.c_str()),1000);
- result.resize( length );
- return result;
- }
- void HideConsole()
- {
- HWND hConsole = FindWindow(STR_CONSOLE_WINDOW_CLASS,GetConsoleTitle().c_str());
- ShowWindow( hConsole, SW_HIDE );
- }
- // Speech.h
- #ifndef _SPEECH_H_
- #define _SPEECH_H_
- #include <SFML/Audio.hpp> // Kniznica pre prehravanie audio stop (sfml-dev.org) + pridat dalsi prepinac compilovania -lsfml-audio -lsfml-system
- #include <SFML/System.hpp> // Kniznica pre metodu sleep
- #include <ctime> // Kniznica pre citanie casu
- #include <string> // Kniznica pre string
- #include <iostream> // Kniznica pre IO operacie
- #include <fstream> // Kniznica pre pracu s subormi
- using namespace std;
- class Speech
- {
- private:
- string plna_cesta,pln_cesta;
- string *name_audio;
- string *tone;
- time_t rawtime;
- tm *timeinfo;
- ifstream inFile;
- public:
- Speech(string *v_name_audio); // Konstruktor koli cestam
- void Play_time(bool &hod, bool &pol_h, bool (&mod)[4], int &volume, int &cas, string &jazyk, string &cesta);// Prehrava audio nahravky casu
- void Play_ton(bool &hod, bool &p_hod, bool (&mod)[4], int &volume, int ton, string cesta); // Prehrava tony
- void Play_date(int &volume, string &cesta_d_t, string &cesta_d, string &cesta_m); // Prehra aktualny datum // Prehrava datum a pod
- void Read_Date(int &dent, int &den, int &mesiac); // zapise cisla dna v tyzdni,mesiaca, dna v mesiaci
- bool Control_time(bool &hod, bool &p_hod, int &cas); // Kontrola aktualneho casu
- bool Read_Config(int &config, const char *meno); // Otvaranie suborov a citanie config nastaveni
- bool Read_set_play(bool (&mod)[4], const char *cesta); // Nastavi styl prehravania zvucky
- bool Language(string &jazyk, const char *cesta); // Nacitanie jazyka
- ~Speech(){}; // Destruktor
- };
- #endif
- // Speech.cpp
- #include "Speech.h"
- Speech::Speech(string *v_name_audio)
- {
- name_audio = v_name_audio;
- }
- void Speech::Play_time(bool &hod, bool &pol_h, bool (&mod)[4], int &volume, int &cas, string &jazyk, string &cesta)
- {
- if (pol_h && mod[1])
- {
- plna_cesta = cesta + "30m.wav";
- sf::Music pol_hodina;
- pol_hodina.OpenFromFile(plna_cesta);
- pln_cesta = cesta + name_audio[cas];
- sf::Music hodina;
- hodina.OpenFromFile(pln_cesta);
- pol_hodina.SetVolume(volume);
- hodina.SetVolume(volume);
- if ((jazyk == "EN") || (jazyk == "DE"))
- {
- pol_hodina.Play();
- while (pol_hodina.GetStatus() == sf::Music::Playing)
- ;
- hodina.Play();
- while (hodina.GetStatus() == sf::Music::Playing)
- sf::Sleep(0.3);
- }
- else
- {
- hodina.Play();
- while (hodina.GetStatus() == sf::Music::Playing)
- ;
- pol_hodina.Play();
- while (pol_hodina.GetStatus() == sf::Music::Playing)
- sf::Sleep(0.3);
- }
- }
- else if (hod && mod[0])
- {
- plna_cesta = cesta + name_audio[cas];
- pln_cesta = cesta + "hour.wav";
- sf::Music cas;
- cas.OpenFromFile(plna_cesta);
- cas.SetVolume(volume);
- if ((jazyk == "EN")||(jazyk == "DE"))
- {
- sf::Music hodina;
- hodina.OpenFromFile(pln_cesta);
- hodina.SetVolume(volume);
- cas.Play();
- while (cas.GetStatus() == sf::Music::Playing)
- ;
- hodina.Play();
- while (hodina.GetStatus() == sf::Music::Playing)
- sf::Sleep(0.1f);
- }
- else
- {
- cas.Play();
- while (cas.GetStatus() == sf::Music::Playing)
- sf::Sleep(0.3);
- }
- }
- }
- void Speech::Play_ton(bool &hod, bool &p_hod, bool (&mod)[4], int &volume, int ton, string cesta)
- {
- if (hod && mod[2] || p_hod && mod[3]) // Oznamuje hodinu, pol hodinu
- {
- plna_cesta = cesta + name_audio[ton];
- sf::SoundBuffer Buffer;
- if (!Buffer.LoadFromFile(plna_cesta))
- std::cout <<"Sound file Not Found!"<<std::endl;
- sf::Sound Sound(Buffer);
- Sound.SetVolume(volume); // Nastavenie hlastitosti
- Sound.Play();
- while (Sound.GetStatus() == sf::Sound::Playing) // Caka pokial sa stopa este prehrava
- {
- sf::Sleep(0.1f);
- }
- }
- }
- void Speech::Play_date(int &volume,string &cesta_d_t, string &cesta_d, string &cesta_m)
- {
- sf::Music tyzden;
- tyzden.OpenFromFile(cesta_d_t);
- sf::Music den;
- den.OpenFromFile(cesta_d);
- sf::Music mesiac;
- mesiac.OpenFromFile(cesta_m);
- tyzden.SetVolume(volume);
- den.SetVolume(volume);
- mesiac.SetVolume(volume);
- // Prehra den v tyzdni
- tyzden.Play();
- while (tyzden.GetStatus() == sf::Music::Playing)
- sf::Sleep(0.2f);
- // Prehra den v mesiaci
- den.Play();
- while (den.GetStatus() == sf::Music::Playing)
- sf::Sleep(0.1);
- // Prehra mesiac
- mesiac.Play();
- while (mesiac.GetStatus() == sf::Music::Playing)
- sf::Sleep(0.3f);
- }
- void Speech::Read_Date(int &dent, int &den, int &mesiac)
- {
- time (&rawtime);
- timeinfo = localtime(&rawtime);
- dent = timeinfo->tm_wday;
- den = timeinfo->tm_mday;
- mesiac = timeinfo->tm_mon;
- }
- bool Speech::Control_time(bool &hod, bool &p_hod, int &cas) // Kontrola casu
- {
- sf::Sleep(1);
- time (&rawtime);
- timeinfo = localtime(&rawtime);
- for (int i = 0;i<=23;i++)
- {
- if ((timeinfo->tm_hour == i) && (timeinfo->tm_min == 30)) // Kontroluje pol hodinu
- {
- cas = i;
- hod = false;
- p_hod = true;
- return true;
- }
- if ((timeinfo->tm_hour == i) && (timeinfo->tm_min == 00)) // Kontroluje celu hodinu
- {
- cas = i;
- hod = true;
- p_hod = false;
- return true;
- }
- }
- return false;
- }
- bool Speech::Read_Config(int &config, const char *cesta)
- {
- inFile.open(cesta);
- if (!(inFile.is_open())) // Kontrola existencie suboru a spravneho otvorenia
- {
- inFile.close();
- return false;
- }
- else
- {
- inFile >> config; // Ak jestvuje nastavi sa moznost podla configu
- inFile.close();
- return true;
- }
- }
- bool Speech::Read_set_play(bool (&mod)[4], const char *cesta) // Nacitanie modu prehravania
- {
- inFile.open(cesta);
- if (!(inFile.is_open())) // Kontrola existencie suboru a spravneho otvorenia
- {
- inFile.close();
- return false;
- }
- else
- {
- char temp;
- for (int i=0;i<4;i++)
- {
- inFile.get(temp); // ziskanie jedneho znaku z config file
- mod[i] = int (temp) - 48; // prekonvertuje char na 1 alebo 0 a nasledne priradi do bool pola
- }
- inFile.close();
- return true;
- }
- }
- bool Speech::Language(string &jazyk, const char *cesta) // Nacitanie jazyka
- {
- string config;
- inFile.open(cesta);
- if (!(inFile.is_open())) // Kontrola existencie suboru a spravneho otvorenia
- {
- inFile.close();
- cout <<"Subor neotvoreny!"<<endl;
- return false;
- }
- else
- {
- inFile >> config;
- if ( config == "EN" || config == "DE" || config == "CZ" ) // Kontrola spravneho nastavenia jazyka
- {
- inFile.close();
- jazyk = config;
- return true;
- }
- else // Pri nespravnom nastaveni sa nastavi default
- {
- inFile.close();
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment