Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- |---------------------------------------|
- | |
- | Created johnyHV |
- | E-mail johnyhvv@gmail.com |
- | |
- | Licence: GNU/GPL |
- | |
- |---------------------------------------|
- --------------------------------------------------------------------------------
- //// main.cpp
- #include <iostream> //Kniznica pre IO operacie
- #include <ctime> //Kniznica pre citanie casu
- #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();
- std::string name_audio[24] = {"00.wav","01.wav","02.wav","03.wav","04.wav","05.wav","06.wav","07.wav","08.wav","09.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"};
- Speech R_Cas(&name_audio[0]);
- bool Tone,Audio;
- string config,home,cesta;
- int Hlasitost,Moznost;
- // Nastavenie ciest pre config
- //cesta = "/SpeechTime/Language/"; // Linux cesta s ulozenym config file
- //home = getenv("HOME"); // Linux ziskava adresu home adresara
- cesta = "\\Program Files\\SpeechTime\\"; // Windows cesta s ulozenym config file
- home = getenv("SYSTEMDRIVE"); // Windows ziskanie particie na ktorej je nainstalovany system
- // kontrola casu a samotne prehratie
- int Hodina;
- for (;;)
- {
- // nacitanie config pre volume
- config = home + cesta + "volume"; // vytvorenie absolutnej cesty configu s nastavenou hlasitostou
- if (!(R_Cas.Read_Config(config.c_str(),Hlasitost))) // nacitanie configu nacitania hlasitosti
- Hlasitost = 100; // Ak nebol nacitany config tak sa nastavi defaultne 100% hlasitost
- // nacitanie config pre mod prehravania
- config = home + cesta + "config"; // Vytvorenie absolutnej cesty pre config stylu prehravania
- if (!(R_Cas.Read_Config(config.c_str(),Moznost))) // nacitanie configu nacita nastavenie
- Moznost = 1; // ak nebol nacitany config tak sa nastavi default... prv pipne potom prehra aktualny cas
- // nastavenie modu prehravania
- R_Cas.Set_play(Moznost,Tone,Audio); // Nastavenie modu prehravania
- if (R_Cas.Control_time(Hodina)) // kontrola casu (celej hodiny)
- {
- R_Cas.Play_ton(Tone,Hlasitost); // prehravanie tonu
- sf::Sleep(0.10); // casove oneskorenie medzi prehravanim
- R_Cas.Play_time(Audio,Hodina,Hlasitost); // prehravanie audio stop
- sf::Sleep(50); // 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.cpp
- #include "speech.h"
- Speech::Speech(std::string *v_name_audio)
- {
- name_audio = v_name_audio;
- //cesta = "/SpeechTime/Language/"; // Linux,
- //home = getenv("HOME"); // Linux ziskava adresu home adresara
- //tone = "tone.wav"; // Linux
- home = getenv("SYSTEMDRIVE"); // Windows ziskanie particie na ktorej je nainstalovany system
- cesta = "\\Program Files\\SpeechTime\\Language\\"; // Windows
- tone = "tone.wav"; // Windows
- }
- void Speech::Play_time(bool &vstup, int &cas, int &volume)
- {
- if (vstup) // Kontrola ci ma spustit prehratie alebo nie
- {
- plna_cesta = home + cesta + name_audio[cas]; // Vytvori sa absolutna cesta s umiestnenim danej stopy
- sf::SoundBuffer Buffer;
- if (!Buffer.LoadFromFile(plna_cesta)) // Otvorenie audio stopy
- std::cout <<"Sound file Not Found!"<<std::endl;
- sf::Sound Sound(Buffer);
- Sound.SetVolume(volume); // Nastavenie hlasitosti
- Sound.Play(); // Spusti prehratie
- while (Sound.GetStatus() == sf::Sound::Playing) // Caka pokial sa stopa este prehrava
- {
- sf::Sleep(0.9f);
- }
- }
- }
- void Speech::Play_ton(bool &vstup, int &volume)
- {
- if (vstup) // Kontrola ci sa ma spustit prehratie alebo nie
- {
- plna_cesta = home + cesta + tone; // Vytvara absolutnu cestu tonu
- sf::SoundBuffer Buffer;
- if (!Buffer.LoadFromFile(plna_cesta)) // Otvorenie audio stopy
- 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);
- }
- }
- }
- bool Speech::Control_time(int &cas)
- {
- sf::Sleep(1);
- time (&rawtime);
- timeinfo = localtime(&rawtime);
- for (int i = 0;i<=23;i++)
- {
- if ((timeinfo->tm_hour == i) && (timeinfo->tm_min == 00)) // Kontroluje ci je cela hodina
- {
- cas = i; // pokial ano, priradi hodnotu hodiny do premennej
- return true; // a vrati true hodnotu pre dalsie spracovanie
- }
- }
- return false; // pokial nieje cela hodina vrati fasle hodnotu
- }
- bool Speech::Read_Config(const char *meno, int &config)
- {
- inFile.open(meno); // otvorenie suboru
- if (!(inFile.is_open())) // Kontrola existencie suboru a spravneho otvorenia
- {
- inFile.close(); // Uyatvori subor
- return false; // Ak sa subor neotvoril vrati false
- }
- else
- {
- inFile >> config; // Ak jestvuje nastavi sa moznost podla configu
- inFile.close(); // Uzatvori subor
- return true; // Vrati navratovu hodnotu true
- }
- }
- void Speech::Set_play(int moznost, bool &tone, bool &audio)
- {
- switch(moznost)
- {
- case 1: // Prehrava sa aj Audio aj Ton
- {
- tone = true;
- audio = true;
- }break;
- case 2: // Prehrava sa len Audio
- {
- tone = false;
- audio = true;
- }break;
- case 3: // Prehrava sa len Ton
- {
- tone = true;
- audio = false;
- }break;
- default: // Ochrana ak by sa nahodou nieco pokazilo
- {
- tone = true;
- audio = true;
- }
- }
- }
- --------------------------------------------------------------------------------
- //// 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
- #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:
- std::string plna_cesta,cesta,tone,home;
- std::string *name_audio; // ukazovatel na string
- time_t rawtime;
- tm *timeinfo; // pointer struktury tm
- ifstream inFile; // objekt pre pracu s suborom
- public:
- Speech(std::string *v_name_audio); // Konstruktor koli cestam
- void Play_time(bool &vstup, int &cas, int &volume); // Prehrava audio nahravky casu
- void Play_ton(bool &vstup, int &volume); // Prehrava tony
- void Sleep(int &cas) { sf::Sleep(cas); }; // Spanok aplikacie
- bool Control_time(int &cas); // Kontrola aktualneho casu
- bool Read_Config(const char *meno, int &config); // Otvaranie suborov a citanie config nastaveni
- void Set_play(int moznost, bool &tone, bool & audio); // Nastavi styl prehravania zvucky
- ~Speech(){}; // Destruktor
- };
- #endif
Advertisement
Add Comment
Please, Sign In to add comment