Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I want to ignore the special characters that the user inputs in a string, while outputting the DTMF signal sound. Basically, I am building a

I want to ignore the special characters that the user inputs in a string, while outputting the DTMF signal sound.

Basically, I am building a DTMF encoder, which for each keypress of a telephone keypad, the system combines a row tone and a column tone and sends both.

For example: "12 34aB-cd$%^&76" should output the tones for "1234abcd76" ignoring spaces and all other characters not found on phone keypad. Is there any quicker and/or easier way to do this?

CODE:

userInput = "12 34aB-cd$%^&76" length = len(userInput) sound = [] index = 0 time = 0.3 delayTime = 0.1 Fs = 8000 runningTime = np.linspace(0,time,time*Fs+1) time2 = np.linspace(0, delayTime, delayTime*Fs+1) lofreq = 0 hifreq = 0 totalfreq = 0 delay = np.sin(2*np.pi*20000*delayTime) while index < length: if userInput[index] == 1: lofreq = np.sin(2*np.pi*697*runningTime) hifreq = np.sin(2*np.pi*1209*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == 2: lofreq = np.sin(2*np.pi*697*runningTime) hifreq = np.sin(2*np.pi*1336*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == 3: lofreq = np.sin(2*np.pi*697*runningTime) hifreq = np.sin(2*np.pi*1447*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == 'A' or 'a': lofreq = np.sin(2*np.pi*697*runningTime) hifreq = np.sin(2*np.pi*1633*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == 4: lofreq = np.sin(2*np.pi*770*runningTime) hifreq = np.sin(2*np.pi*1209*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == 5: lofreq = np.sin(2*np.pi*770*runningTime) hifreq = np.sin(2*np.pi*1336*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == 6: lofreq = np.sin(2*np.pi*770*runningTime) hifreq = np.sin(2*np.pi*1447*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == 'B' or 'b': lofreq = np.sin(2*np.pi*770*runningTime) hifreq = np.sin(2*np.pi*1633*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == 7: lofreq = np.sin(2*np.pi*852*runningTime) hifreq = np.sin(2*np.pi*1209*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == 8: lofreq = np.sin(2*np.pi*852*runningTime) hifreq = np.sin(2*np.pi*1336*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == 9: lofreq = np.sin(2*np.pi*852*runningTime) hifreq = np.sin(2*np.pi*1477*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == 'C' or 'c': lofreq = np.sin(2*np.pi*852*runningTime) hifreq = np.sin(2*np.pi*1633*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == '*': lofreq = np.sin(2*np.pi*941*runningTime) hifreq = np.sin(2*np.pi*1209*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == 0: lofreq = np.sin(2*np.pi*941*runningTime) hifreq = np.sin(2*np.pi*1336*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == '#': lofreq = np.sin(2*np.pi*941*runningTime) hifreq = np.sin(2*np.pi*1447*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) elif userInput[index] == 'D' or 'd': lofreq = np.sin(2*np.pi*941*runningTime) hifreq = np.sin(2*np.pi*1633*runningTime) totalfreq = lofreq + hifreq sound.append(lofreq + hifreq) sound.append(delay) index = index + 1 

sound_out = np.concatenate(sound)

print(sound_out)

Audio(sound_out,rate = Fs)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions