i need to figure out how to add an if..elseif..elseif statement to play differen
ID: 3670079 • Letter: I
Question
i need to figure out how to add an if..elseif..elseif statement to play different sound files based on the user input value
this is what i have so far.
disp('Press A to play automatic speech program')
disp('Press any other key to manually control what to say')
input('Enter your selection:')
disp('1 - Check out whats new 5 - Irritate me 9 - Game show buzzer')
disp('2 - PacMan death 6 - About time 10 - The price is wrong')
disp('3 - Buy one get one free 7 - Hard drive crash 11 - Final Countdown')
disp('4 - Hasta la vista 8 - Ms Pacman death 12 - Goodbye')
disp('Press 12 to say goodbye or enter the voice number to play a voice:')
if
[y,Fs] = audioread('check_out_whats_new.wav');
sound(y,Fs)
end
if
[y,Fs] = audioread('pacman_death.wav');
sound(y,Fs)
end
Explanation / Answer
%Matlab -program to prompt user to enter the user choice and select
%the appropriate song (replace with song files in from userchoice=3 on wards )
%with your own audion files.
%save this file as audio.m
disp('Press A to play automatic speech program')
disp('Press any other key to manually control what to say')
disp('1 - Check out whats new 5 - Irritate me 9 - Game show buzzer')
disp('2 - PacMan death 6 - About time 10 - The price is wrong')
disp('3 - Buy one get one free 7 - Hard drive crash 11 - Final Countdown')
disp('4 - Hasta la vista 8 - Ms Pacman death 12 - Goodbye')
disp('Press 12 to say goodbye or enter the voice number to play a voice:')
%prompt user to enter choice of input type
userchoice=input('Enter your selection:');
%Use if elseif end nested if statement to select the appropriate user choice
if userchoice==1
[y,Fs] = audioread('check_out_whats_new.wav');
sound(y,Fs)
elseif userchoice==2
[y,Fs] = audioread('pacman_death.wav');
sound(y,Fs)
elseif userchoice==3
[y,Fs] = audioread('pacman_death.wav');
sound(y,Fs)
elseif userchoice==4
[y,Fs] = audioread('pacman_death.wav');
sound(y,Fs)
elseif userchoice==5
[y,Fs] = audioread('pacman_death.wav');
sound(y,Fs)
elseif userchoice==6
[y,Fs] = audioread('pacman_death.wav');
sound(y,Fs)
elseif userchoice==7
[y,Fs] = audioread('pacman_death.wav');
sound(y,Fs)
elseif userchoice==8
[y,Fs] = audioread('pacman_death.wav');
sound(y,Fs)
elseif userchoice==9
[y,Fs] = audioread('pacman_death.wav');
sound(y,Fs)
elseif userchoice==10
[y,Fs] = audioread('pacman_death.wav');
sound(y,Fs)
elseif userchoice==11
[y,Fs] = audioread('pacman_death.wav');
sound(y,Fs)
elseif userchoice==12
disp 'Good bye!'
end
---------------------------------------------------------------------------------------------------------------------------------------------------
Sample output:
Note: From the Matlab command prompt, write the file name as audio to run the file
--> audio
Press A to play automatic speech program
Press any other key to manually control what to say
1 - Check out whats new 5 - Irritate me 9 - Game show buzzer
2 - PacMan death 6 - About time 10 - The price is wrong
3 - Buy one get one free 7 - Hard drive crash 11 - Final Countdown
4 - Hasta la vista 8 - Ms Pacman death 12 - Goodbye
Press 12 to say goodbye or enter the voice number to play a voice:
Enter your selection:12
Good bye!
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.