Fidell Posted March 25, 2012 at 03:02 PM Report #445578 Posted March 25, 2012 at 03:02 PM Boa tarde amigos, Estou com uma dúvida enorme, e nao consigo encontrar nenhuma informção para o meu projecto. O meu projecto consiste numa montagem de um circuito com o Arduino Uno( linguagem C++) e com uma Wave shield (onde estará armazenado os ficheiros de som). Tenho montado uns botões de pressão que ao carregar no primeiro ele abre um ficheiro de som, onde emite o som da Introdução gravada por mim em ficheiro (.Wav). Agora gostaria de saber um código para que no botão seguinte ao carregar ele abri-se um ficheiro que dizia "são Jorge" mas não era este o ficheiro que queria ouvir, então carregar novamente no mesmo botão e este dizer outro som como por exemplo "são Nicolau" e era o som pretendido, então este ficaria seleccionado e abriria a informação que continha o som "são Nicolau". Alguém me poderá ajudar se faz favor? é muito importante Cumprimentos, aguardo ajudas
bsccara Posted March 25, 2012 at 04:01 PM Report #445583 Posted March 25, 2012 at 04:01 PM Já tens algum código feito ? Já consegues reproduzir ficheiros WAV ?
Fidell Posted March 25, 2012 at 06:54 PM Author Report #445605 Posted March 25, 2012 at 06:54 PM Sim já tenho algum código feito 😄 e já tenho o botão de introdução feito e a produzir o som . So me faltava mesmo para este botão fazer o seguinte e seleccionar o ficheiro pretendido para abrir o que for seleccionado. O meu código feito ate agora esta aqui: https://hotfile.com/dl/150203462/ae68c77/PAP_Andr__V00.pde.html
bsccara Posted March 25, 2012 at 11:15 PM Report #445652 Posted March 25, 2012 at 11:15 PM A ver se percebo: queres ler os ficheiros presentes no sistema de ficheiros detectado por setup e dizer os nomes deles e esperar confirmação pelos botões ou as frases a dizer ('são...') seriam previamente gravadas ?
JD557 Posted March 26, 2012 at 09:02 AM Report #445676 Posted March 26, 2012 at 09:02 AM Não entendi se queres implementar um sintetizador de fala no arduino. Não sei se tal é possível, mas se for, presumo que o melhor seja baseares-te neste projecto: http://pouet.net/prod.php?which=50530 (O download inclui a source code) MIEIC @ FEUP http://project557.blogspot.com/ --- Development Blog Proteja a sua pen: http://lastknight.pt.vu
Fidell Posted March 26, 2012 at 11:55 AM Author Report #445701 Posted March 26, 2012 at 11:55 AM Sim...ao carregar no botão de pressão este começa a emitir o som, mas se não é o destino desejado este deve carregar novamente no botão para passar a instrução seguinte, e assim sucessivamente até encontrar o destino pretendido :S é só o que me falta fazer.
bsccara Posted March 26, 2012 at 12:32 PM Report #445706 Posted March 26, 2012 at 12:32 PM Sim...ao carregar no botão de pressão este começa a emitir o som, mas se não é o destino desejado este deve carregar novamente no botão para passar a instrução seguinte, e assim sucessivamente até encontrar o destino pretendido :S é só o que me falta fazer. OK, mas o som é pré-gravado ou criado na altura ? Para sintetizar voz também tens o projecto CMU FLite (http://www.speech.cs.cmu.edu/flite/) mas não consegues meter isso no Arduino.
Fidell Posted March 26, 2012 at 02:37 PM Author Report #445727 Posted March 26, 2012 at 02:37 PM Não o som já esta gravado num cartão de memoria... ele só terá de abrir o som mediante o que o utilizador quiser, ao carregar no botão
bsccara Posted March 26, 2012 at 05:32 PM Report #445749 Posted March 26, 2012 at 05:32 PM Então terás de usar algum método da API para ler o conteúdo do cartão, meter cada nome de ficheiro num array ou coisa semelhante que possa ser acedida por um indice, inicializar o indice para o primeiro elemento e reproduzir o som. A cada pressão no botão incrementas o índice, páras a reprodução se estiver a decorrer e reproduzes o novo ficheiro. Quanto o índice ultrapassar o nº de elementos, voltas a pô-lo para o primeiro elemento (nome de ficheiro). Tirando a leitura do cartão o resto é muito simples. Ou então não estou a perceber o que queres fazer...
Fidell Posted March 26, 2012 at 07:15 PM Author Report #445761 Posted March 26, 2012 at 07:15 PM Sim é isso...mas não estou a ver como isso se faz...já meti os sons nos arrays...só não sei fazer o passo seguinte :S Consegues ajudar?
bsccara Posted March 26, 2012 at 11:10 PM Report #445817 Posted March 26, 2012 at 11:10 PM Poê aqui o código que tens, só a parte em que metes os nomes dos ficheiros no array e a rotina em que lês os botões e queres reproduzir os sons. Outras funções resume-as a uma descrição só, pois grandes volumes de código levam demasiado tempo a analisar.
Fidell Posted March 27, 2012 at 11:25 AM Author Report #445885 Posted March 27, 2012 at 11:25 AM É este o Código. o que esta atrás não interessa.. // if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you if (!card.init()) { //play with 8 MHz spi (default faster!) putstring_nl("Card init. failed!"); // Something went wrong, lets print out why sdErrorCheck(); while(1); // then 'halt' - do nothing! } // enable optimize read - some cards may timeout. Disable if you're having problems card.partialBlockRead(true); // Now we will look for a FAT partition! uint8_t part; for (part = 0; part < 5; part++) { // we have up to 5 slots to look in if (vol.init(card, part)) break; // we found one, lets bail } if (part == 5) { // if we ended up not finding one putstring_nl("No valid FAT partition!"); sdErrorCheck(); // Something went wrong, lets print out why while(1); // then 'halt' - do nothing! } // Lets tell the user about what we found putstring("Using partition "); Serial.print(part, DEC); putstring(", type is FAT"); Serial.println(vol.fatType(),DEC); // FAT16 or FAT32? // Try to open the root directory if (!root.openRoot(vol)) { putstring_nl("Can't open root dir!"); // Something went wrong, while(1); // then 'halt' - do nothing! } // Whew! We got past the tough parts. putstring_nl("Ready!"); } void loop() { //putstring("."); // uncomment this to see if the loop isnt running switch (check_switches()) { case 1: playcomplete("SOUND1.WAV"); break; case 2: playcomplete("SOUND2.WAV"); break; case 3: playcomplete("SOUND3.WAV"); break; case 4: playcomplete("SOUND4.WAV"); break; case 5: playcomplete("SOUND5.WAV"); break; case 6: playcomplete("SOUND6.WAV"); } } byte check_switches() { static byte previous[6]; static long time[6]; byte reading; byte pressed; byte index; pressed = 0; for (byte index = 0; index < 6; ++index) { reading = digitalRead(14 + index); if (reading == LOW && previous[index] == HIGH && millis() - time[index] > DEBOUNCE) { // switch pressed time[index] = millis(); pressed = index + 1; break; } previous[index] = reading; } // return switch number (1 - 6) return (pressed); } // Plays a full file from beginning to end with no pause. void playcomplete(char *name) { // call our helper to find and play this name playfile(name); while (wave.isplaying) { // do nothing while its playing } // now its done playing } void playfile(char *name) { // see if the wave object is currently doing something if (wave.isplaying) {// already playing something, so stop it! wave.stop(); // stop it } // look in the root directory and open the file if (!f.open(root, name)) { putstring("Couldn't open file "); Serial.print(name); return; } // OK read the file and turn it into a wave object if (!wave.create(f)) { putstring_nl("Not a valid WAV"); return; } // ok time to play! start playback wave.play(); }
bsccara Posted March 27, 2012 at 11:57 AM Report #445891 Posted March 27, 2012 at 11:57 AM Este já tinha visto. Tens alguma função 'main' criada ?
Fidell Posted March 27, 2012 at 12:18 PM Author Report #445895 Posted March 27, 2012 at 12:18 PM Este é todo o código que tenho criado... #include <FatReader.h> #include <SdReader.h> #include <avr/pgmspace.h> #include "WaveUtil.h" #include "WaveHC.h" SdReader card; // This object holds the information for the card FatVolume vol; // This holds the information for the partition on the card FatReader root; // This holds the information for the filesystem on the card FatReader f; // This holds the information for the file we're play WaveHC wave; // This is the only wave (audio) object, since we will only play one at a time #define DEBOUNCE 100 // button debouncer // this handy function will return the number of bytes currently free in RAM, great for debugging! int freeRam(void) { extern int __bss_end; extern int *__brkval; int free_memory; if((int)__brkval == 0) { free_memory = ((int)&free_memory) - ((int)&__bss_end); } else { free_memory = ((int)&free_memory) - ((int)__brkval); } return free_memory; } void sdErrorCheck(void) { if (!card.errorCode()) return; putstring("\n\rSD I/O error: "); Serial.print(card.errorCode(), HEX); putstring(", "); Serial.println(card.errorData(), HEX); while(1); } void setup() { // set up serial port Serial.begin(9600); putstring_nl("WaveHC with 6 buttons"); putstring("Free RAM: "); // This can help with debugging, running out of RAM is bad Serial.println(freeRam()); // if this is under 150 bytes it may spell trouble! // Set the output pins for the DAC control. This pins are defined in the library pinMode(2, OUTPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); // pin13 LED pinMode(13, OUTPUT); // enable pull-up resistors on switch pins (analog inputs) digitalWrite(14, HIGH); digitalWrite(15, HIGH); digitalWrite(16, HIGH); digitalWrite(17, HIGH); digitalWrite(18, HIGH); digitalWrite(19, HIGH); // if (!card.init(true)) { //play with 4 MHz spi if 8MHz isn't working for you if (!card.init()) { //play with 8 MHz spi (default faster!) putstring_nl("Card init. failed!"); // Something went wrong, lets print out why sdErrorCheck(); while(1); // then 'halt' - do nothing! } // enable optimize read - some cards may timeout. Disable if you're having problems card.partialBlockRead(true); // Now we will look for a FAT partition! uint8_t part; for (part = 0; part < 5; part++) { // we have up to 5 slots to look in if (vol.init(card, part)) break; // we found one, lets bail } if (part == 5) { // if we ended up not finding one putstring_nl("No valid FAT partition!"); sdErrorCheck(); // Something went wrong, lets print out why while(1); // then 'halt' - do nothing! } // Lets tell the user about what we found putstring("Using partition "); Serial.print(part, DEC); putstring(", type is FAT"); Serial.println(vol.fatType(),DEC); // FAT16 or FAT32? // Try to open the root directory if (!root.openRoot(vol)) { putstring_nl("Can't open root dir!"); // Something went wrong, while(1); // then 'halt' - do nothing! } // Whew! We got past the tough parts. putstring_nl("Ready!"); } void loop() { //putstring("."); // uncomment this to see if the loop isnt running switch (check_switches()) { case 1: playcomplete("SOUND1.WAV"); break; case 2: playcomplete("SOUND2.WAV"); break; case 3: playcomplete("SOUND3.WAV"); break; case 4: playcomplete("SOUND4.WAV"); break; case 5: playcomplete("SOUND5.WAV"); break; case 6: playcomplete("SOUND6.WAV"); } } byte check_switches() { static byte previous[6]; static long time[6]; byte reading; byte pressed; byte index; pressed = 0; for (byte index = 0; index < 6; ++index) { reading = digitalRead(14 + index); if (reading == LOW && previous[index] == HIGH && millis() - time[index] > DEBOUNCE) { // switch pressed time[index] = millis(); pressed = index + 1; break; } previous[index] = reading; } // return switch number (1 - 6) return (pressed); } // Plays a full file from beginning to end with no pause. void playcomplete(char *name) { // call our helper to find and play this name playfile(name); while (wave.isplaying) { // do nothing while its playing } // now its done playing } void playfile(char *name) { // see if the wave object is currently doing something if (wave.isplaying) {// already playing something, so stop it! wave.stop(); // stop it } // look in the root directory and open the file if (!f.open(root, name)) { putstring("Couldn't open file "); Serial.print(name); return; } // OK read the file and turn it into a wave object if (!wave.create(f)) { putstring_nl("Not a valid WAV"); return; } // ok time to play! start playback wave.play(); }
bsccara Posted March 27, 2012 at 12:41 PM Report #445900 Posted March 27, 2012 at 12:41 PM Em vez desse código, que provavelmente foste buscar ao mesmo sítio, estuda este : http://www.ladyada.net/media/wavshield/daphc.pde. Este exemplo toca todos os ficheiros que encontrar no cartão. Depois junta-lhe a função 'check_switches' e usa-a dentro da 'play' para saltar de ficheiro.
Fidell Posted March 27, 2012 at 01:07 PM Author Report #445909 Posted March 27, 2012 at 01:07 PM Mas so salta de ficheiro se nos carregarmos no botao?
bsccara Posted March 27, 2012 at 02:29 PM Report #445937 Posted March 27, 2012 at 02:29 PM O exemplo que te indiquei não liga patavina aos botões; lê a partição FAT e reproduz tudo o que encontrar, entrando nas directorias que existam. Dentro da função 'play' há um ciclo que espera pelo final da reprodução de cada ficheiro; é nesse ciclo que podes ler os botões e interromper a reprodução com o 'wave.stop'. Fazendo isso o código passará para o seguinte.
Fidell Posted March 27, 2012 at 03:29 PM Author Report #445972 Posted March 27, 2012 at 03:29 PM Não me podes dar uma ideia de como ficará mais ao menos só para um exemplo no meu código sff?
bsccara Posted March 27, 2012 at 11:33 PM Report #446045 Posted March 27, 2012 at 11:33 PM Quase no fim do código que te indiquei tens : while (wave.isplaying) { // playing occurs in interrupts, so we print dots in realtime putstring("."); delay(100); } Mudas para : while (wave.isplaying) { // playing occurs in interrupts, so we print dots in realtime if (check_switches() == 1) wave.stop(); else delay(100); } De qualquer maneira, espero que estudes a documentação da biblioteca WaveHC (http://code.google.com/p/wavehc/) para perceberes o que se passa no código. Dentro do pacote de código existem uns HTML com a descrição (muito sucinta, mas enfim) das classes.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now