├── .gitignore ├── AudioAnalysis ├── .gitignore ├── README.md ├── SupervisedLearning.ipynb ├── Visualize.ipynb ├── google_samples │ ├── attack │ │ ├── google_Inaudible_SuperBowlWins.wav │ │ ├── google_Inaudible_TakeAPic.wav │ │ └── google_Inaudible_WhatsTheTemp.wav │ ├── normal │ │ ├── google_normal_PlayFamousSuperBowlAds.wav │ │ ├── google_normal_WhatsTheTemperatureNow.wav │ │ └── google_normal_takeAPicture.wav │ └── test │ │ ├── google_Inaudible_SetAlarm.wav │ │ └── google_normal_SetAlarm11.wav ├── record.py ├── samples │ ├── google_attacks │ │ ├── BookFlightVegas.wav │ │ ├── Call18002262278.wav │ │ ├── CallComcast.wav │ │ ├── CallSadullah.wav │ │ ├── EmailSadullah.wav │ │ ├── HowFarFromBUEE.wav │ │ ├── HowManySuperBowlsPatroitsWin.wav │ │ ├── MuteMyPhone.wav │ │ ├── OpenBUedu.wav │ │ ├── OpenCNN.wav │ │ ├── OpenCitibankApp.wav │ │ ├── OpenFacebook.wav │ │ ├── PlayFamousSuperBowlAds.wav │ │ ├── PlayShakiraYoutube.wav │ │ ├── SetAlarm11.wav │ │ ├── TakeAPicture.wav │ │ ├── TextSadullah.wav │ │ ├── TrophiesManchesterUnited.wav │ │ ├── WhatsTheTempratureNow.wav │ │ ├── bank_of_america.wav │ │ └── glory_manu.wav │ ├── google_normal │ │ ├── google_normal_BookFlightVegas.wav │ │ ├── google_normal_Call18002262278.wav │ │ ├── google_normal_CallComcast.wav │ │ ├── google_normal_CallSadullah.wav │ │ ├── google_normal_EmailSadullah.wav │ │ ├── google_normal_GloryManUnitedYoutube.wav │ │ ├── google_normal_HowFarFromBUEE.wav │ │ ├── google_normal_HowManySuperBowlsPatriotsWin.wav │ │ ├── google_normal_MuteMyPhone.wav │ │ ├── google_normal_OpenBUedu.wav │ │ ├── google_normal_OpenBankOfAmericaApp.wav │ │ ├── google_normal_OpenCNN.wav │ │ ├── google_normal_OpenCitibankApp.wav │ │ ├── google_normal_OpenFacebook.wav │ │ ├── google_normal_PlayFamousSuperBowlAds.wav │ │ ├── google_normal_PlayShakiraYoutube.wav │ │ ├── google_normal_SetAlarm11.wav │ │ ├── google_normal_TextSadullah.wav │ │ ├── google_normal_TrophiesManchesterUnited.wav │ │ ├── google_normal_WhatsTheTemperatureNow.wav │ │ └── google_normal_takeAPicture.wav │ ├── location_normal.wav │ ├── shreeya_take_picture.wav │ └── statue_normal.wav └── wav_samples │ ├── attack_alexa_how_are_you.wav │ ├── attack_answer_the_call.wav │ ├── attack_buy_justin.wav │ ├── attack_buy_love_yourself.wav │ ├── attack_cancel_8am_alarm.wav │ ├── attack_clear_my_calender.wav │ ├── attack_delete_all_notifications.wav │ ├── attack_end_the_call.wav │ ├── attack_hang_up.wav │ ├── attack_message_sadullah.wav │ ├── normal_alexa_how_are_you.wav │ ├── normal_answer_the_call.wav │ ├── normal_buy_justin.wav │ ├── normal_buy_love_yourself.wav │ ├── normal_cancel_8am_alarm.wav │ ├── normal_clear_my_calender.wav │ ├── normal_delete_all_notifications.wav │ ├── normal_end_the_call.wav │ ├── normal_hang_up.wav │ └── normal_message_sadullah.wav ├── Dolphin.m ├── README.md ├── RecordAttacks ├── .gitignore ├── .idea │ ├── gradle.xml │ ├── misc.xml │ ├── modules.xml │ └── runConfigurations.xml ├── README.md ├── app │ ├── .gitignore │ ├── CMakeLists.txt │ ├── build.gradle │ ├── proguard-rules.pro │ └── src │ │ ├── androidTest │ │ └── java │ │ │ └── com │ │ │ └── example │ │ │ └── skhad │ │ │ └── recordattacks │ │ │ └── ExampleInstrumentedTest.java │ │ ├── main │ │ ├── AndroidManifest.xml │ │ ├── cpp │ │ │ └── native-lib.cpp │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── skhad │ │ │ │ └── recordattacks │ │ │ │ └── MainActivity.java │ │ └── res │ │ │ ├── drawable-v24 │ │ │ └── ic_launcher_foreground.xml │ │ │ ├── drawable │ │ │ └── ic_launcher_background.xml │ │ │ ├── layout │ │ │ └── activity_main.xml │ │ │ ├── mipmap-anydpi-v26 │ │ │ ├── ic_launcher.xml │ │ │ └── ic_launcher_round.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ └── values │ │ │ ├── colors.xml │ │ │ ├── strings.xml │ │ │ └── styles.xml │ │ └── test │ │ └── java │ │ └── com │ │ └── example │ │ └── skhad │ │ └── recordattacks │ │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle ├── RunDolphin.m └── WorkingCases ├── Alexa_Samples ├── 192K_Ultrasound │ └── Alexa_Hacked.wav └── 48K_Normalsound │ └── Alexa.m4a ├── GoogleAssistant ├── MutePhone.wav ├── SetAlarm.wav └── WhatsTheTemp.wav └── Siri_Samples └── Siri_WhatsMyName.wav /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /AudioAnalysis/.gitignore: -------------------------------------------------------------------------------- 1 | .ipynb_checkpoints 2 | *Trial.* 3 | -------------------------------------------------------------------------------- /AudioAnalysis/README.md: -------------------------------------------------------------------------------- 1 | # Audio Analysis 2 | 3 | ## Recording Samples 4 | 5 | ### Dependencies 6 | Python 3.5+ 7 | 8 | Librosa 9 | 10 | matplotlib 11 | 12 | numpy 13 | 14 | ### Recording 15 | ```bash 16 | python record.py _ 17 | ``` 18 | 19 | Example: 20 | ```bash 21 | python record.py attack_alexa_how_are_you.wav 22 | python record.py normal_alexa_how_are_you.wav 23 | ``` 24 | 25 | Audio sample will be stored in **wav_samples** folder 26 | 27 | ### Visualization 28 | Visualize.ipynb 29 | 30 | ### Logistic Regresion Model 31 | SupervisedLearning.ipynb 32 | -------------------------------------------------------------------------------- /AudioAnalysis/google_samples/attack/google_Inaudible_SuperBowlWins.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/google_samples/attack/google_Inaudible_SuperBowlWins.wav -------------------------------------------------------------------------------- /AudioAnalysis/google_samples/attack/google_Inaudible_TakeAPic.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/google_samples/attack/google_Inaudible_TakeAPic.wav -------------------------------------------------------------------------------- /AudioAnalysis/google_samples/attack/google_Inaudible_WhatsTheTemp.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/google_samples/attack/google_Inaudible_WhatsTheTemp.wav -------------------------------------------------------------------------------- /AudioAnalysis/google_samples/normal/google_normal_PlayFamousSuperBowlAds.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/google_samples/normal/google_normal_PlayFamousSuperBowlAds.wav -------------------------------------------------------------------------------- /AudioAnalysis/google_samples/normal/google_normal_WhatsTheTemperatureNow.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/google_samples/normal/google_normal_WhatsTheTemperatureNow.wav -------------------------------------------------------------------------------- /AudioAnalysis/google_samples/normal/google_normal_takeAPicture.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/google_samples/normal/google_normal_takeAPicture.wav -------------------------------------------------------------------------------- /AudioAnalysis/google_samples/test/google_Inaudible_SetAlarm.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/google_samples/test/google_Inaudible_SetAlarm.wav -------------------------------------------------------------------------------- /AudioAnalysis/google_samples/test/google_normal_SetAlarm11.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/google_samples/test/google_normal_SetAlarm11.wav -------------------------------------------------------------------------------- /AudioAnalysis/record.py: -------------------------------------------------------------------------------- 1 | """Program to record a few seconds of audio and save to a WAVE file.""" 2 | 3 | import pyaudio 4 | import wave 5 | import sys 6 | import numpy as np 7 | 8 | CHUNK = 1024 9 | FORMAT = pyaudio.paInt16 10 | CHANNELS = 2 11 | RATE = 48000 12 | RECORD_SECONDS = 6 13 | 14 | WAVE_OUTPUT_FILENAME = sys.argv[1] 15 | 16 | p = pyaudio.PyAudio() 17 | 18 | stream = p.open(format=FORMAT, 19 | channels=CHANNELS, 20 | rate=RATE, 21 | input=True, 22 | frames_per_buffer=CHUNK) 23 | 24 | print("* recording") 25 | 26 | frames = [] 27 | 28 | for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): 29 | data = stream.read(CHUNK) 30 | data_array = np.fromstring(data, dtype=np.int16) 31 | #print (np.max(data_array)) 32 | frames.append(data) 33 | 34 | print("* done recording") 35 | 36 | stream.stop_stream() 37 | stream.close() 38 | p.terminate() 39 | 40 | wf = wave.open('./wav_samples/'+WAVE_OUTPUT_FILENAME, 'wb') 41 | wf.setnchannels(CHANNELS) 42 | wf.setsampwidth(p.get_sample_size(FORMAT)) 43 | wf.setframerate(RATE) 44 | wf.writeframes(b''.join(frames)) 45 | wf.close() 46 | -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/BookFlightVegas.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/BookFlightVegas.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/Call18002262278.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/Call18002262278.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/CallComcast.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/CallComcast.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/CallSadullah.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/CallSadullah.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/EmailSadullah.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/EmailSadullah.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/HowFarFromBUEE.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/HowFarFromBUEE.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/HowManySuperBowlsPatroitsWin.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/HowManySuperBowlsPatroitsWin.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/MuteMyPhone.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/MuteMyPhone.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/OpenBUedu.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/OpenBUedu.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/OpenCNN.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/OpenCNN.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/OpenCitibankApp.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/OpenCitibankApp.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/OpenFacebook.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/OpenFacebook.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/PlayFamousSuperBowlAds.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/PlayFamousSuperBowlAds.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/PlayShakiraYoutube.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/PlayShakiraYoutube.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/SetAlarm11.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/SetAlarm11.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/TakeAPicture.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/TakeAPicture.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/TextSadullah.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/TextSadullah.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/TrophiesManchesterUnited.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/TrophiesManchesterUnited.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/WhatsTheTempratureNow.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/WhatsTheTempratureNow.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/bank_of_america.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/bank_of_america.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_attacks/glory_manu.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_attacks/glory_manu.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_BookFlightVegas.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_BookFlightVegas.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_Call18002262278.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_Call18002262278.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_CallComcast.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_CallComcast.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_CallSadullah.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_CallSadullah.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_EmailSadullah.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_EmailSadullah.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_GloryManUnitedYoutube.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_GloryManUnitedYoutube.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_HowFarFromBUEE.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_HowFarFromBUEE.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_HowManySuperBowlsPatriotsWin.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_HowManySuperBowlsPatriotsWin.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_MuteMyPhone.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_MuteMyPhone.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_OpenBUedu.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_OpenBUedu.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_OpenBankOfAmericaApp.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_OpenBankOfAmericaApp.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_OpenCNN.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_OpenCNN.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_OpenCitibankApp.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_OpenCitibankApp.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_OpenFacebook.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_OpenFacebook.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_PlayFamousSuperBowlAds.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_PlayFamousSuperBowlAds.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_PlayShakiraYoutube.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_PlayShakiraYoutube.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_SetAlarm11.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_SetAlarm11.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_TextSadullah.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_TextSadullah.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_TrophiesManchesterUnited.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_TrophiesManchesterUnited.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_WhatsTheTemperatureNow.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_WhatsTheTemperatureNow.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/google_normal/google_normal_takeAPicture.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/google_normal/google_normal_takeAPicture.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/location_normal.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/location_normal.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/shreeya_take_picture.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/shreeya_take_picture.wav -------------------------------------------------------------------------------- /AudioAnalysis/samples/statue_normal.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/samples/statue_normal.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/attack_alexa_how_are_you.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/attack_alexa_how_are_you.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/attack_answer_the_call.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/attack_answer_the_call.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/attack_buy_justin.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/attack_buy_justin.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/attack_buy_love_yourself.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/attack_buy_love_yourself.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/attack_cancel_8am_alarm.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/attack_cancel_8am_alarm.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/attack_clear_my_calender.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/attack_clear_my_calender.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/attack_delete_all_notifications.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/attack_delete_all_notifications.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/attack_end_the_call.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/attack_end_the_call.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/attack_hang_up.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/attack_hang_up.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/attack_message_sadullah.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/attack_message_sadullah.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/normal_alexa_how_are_you.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/normal_alexa_how_are_you.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/normal_answer_the_call.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/normal_answer_the_call.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/normal_buy_justin.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/normal_buy_justin.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/normal_buy_love_yourself.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/normal_buy_love_yourself.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/normal_cancel_8am_alarm.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/normal_cancel_8am_alarm.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/normal_clear_my_calender.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/normal_clear_my_calender.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/normal_delete_all_notifications.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/normal_delete_all_notifications.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/normal_end_the_call.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/normal_end_the_call.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/normal_hang_up.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/normal_hang_up.wav -------------------------------------------------------------------------------- /AudioAnalysis/wav_samples/normal_message_sadullah.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/scanakci/DolphinAttack/69aa1864c340e02ef8a9887fce6ff88aa568dfa3/AudioAnalysis/wav_samples/normal_message_sadullah.wav -------------------------------------------------------------------------------- /Dolphin.m: -------------------------------------------------------------------------------- 1 | function Dolphin(inputFile,outputFile,plotMode,n1,n2,tmax) 2 | 3 | %% Dolphin Attack 4 | % Idea is detailed in : 5 | % Inaudible Voice Commands 6 | % Liwei Song, Prateek Mittal liweis@princeton.edu, 7 | % pmittal@princeton.edu Department of Electrical Engineering, 8 | % Princeton University 9 | 10 | %% Input Parameters 11 | %inputFile-> The name of the input file to be processed ( make sure that it 12 | %is one channel and has 48KhZ sampling rate) 13 | %n1-> Amplification ratio 1, may need to fine tune by investigating signal 14 | %n2-> Amplification ratio 2, may need to fine tune by investigating signal 15 | %outputFile-> the name of the outputFile(Attack signal) 16 | %plotMode-> set to 1 if you want to see plots to investigate signals 17 | %tmax-> for how many seconds you wanna draw your plots? 18 | 19 | if (nargin < 2) 20 | Disp('Please at least provide your input and outputfile names!!!') 21 | elseif (nargin == 2) % Default values for n1 and n2 22 | n1 = 0.5; 23 | n2 = 0.5; 24 | plotMode = 0; 25 | tmax = 5; 26 | end 27 | 28 | %% Normal Signal such as 'OK GOOGLE', 'ALEXA' 29 | [Snormal, Fs] = audioread(inputFile); 30 | %[Snormal2, Fs] = audioread('Alexa.m4a'); 31 | Snormal = Snormal (:,1); 32 | 33 | if ( plotMode == 1) 34 | subplot 211 35 | stem(0:tmax*Fs-1,Snormal(1:tmax*Fs),'filled','markersize',3) % this should be dynamic too!!!! 36 | grid on 37 | xlabel 'Sample number:48000',ylabel Original 38 | end 39 | 40 | %% Low-Pass Filtering 41 | % Adopt a low-pass filter on the normal signal, with the cut-off frequency 42 | % as 8kHz to remove high frequency components 43 | Fp = 8e3; % 8 kHz passband-edge frequency 44 | Fs = 48e3; % 48 kHz sampling frequency 45 | Rp = 0.00057565; % Corresponds to 0.01 dB peak-to-peak ripple 46 | Rst = 1e-4; % Corresponds to 80 dB stopband attenuation 47 | 48 | Fst = 9e3; % Transition Width = Fst - Fp 49 | numMinOrder = firgr('minorder',[0,Fp/(Fs/2),Fst/(Fs/2),1],[1 1 0 0],... 50 | [Rp Rst]); % useful function to determine numMinOrder 51 | 52 | if(plotMode) 53 | fvt = fvtool(numMinOrder,1,'Fs',Fs,'Color','White'); 54 | legend(fvt,'FIR filter. Order = 133') 55 | end 56 | 57 | lowpassFIR = dsp.FIRFilter('Numerator',numMinOrder); % Design Low pass Filter 58 | Sfilter = lowpassFIR(Snormal); % Apply low pass filter 59 | 60 | %tmax = 5; plot for 5 seconds input to function 61 | Nsamps = tmax*Fs; 62 | t = 1/Fs:1/Fs:tmax; 63 | 64 | if ( plotMode == 1) 65 | %Plot in Time Domain 66 | %Original 67 | figure 68 | plot(t,Snormal(1:Fs*tmax)) 69 | xlabel('Time (s)') 70 | ylabel('Amplitude (V)') 71 | title('Original Signal') 72 | 73 | figure 74 | spectrogram(Snormal,128,120,128,1e5,'yaxis') 75 | %Filtered 76 | figure 77 | plot(t,Sfilter(1:Fs*tmax)) 78 | xlabel('Time (s)') 79 | ylabel('Amplitude (V)') 80 | title('Filtered Signal') 81 | 82 | %Frequency Domain 83 | 84 | f = Fs*(0:Nsamps/2-1)/Nsamps; %Prepare freq data for plot 85 | 86 | %Normal 87 | Snormal_fft = abs(fft(Snormal)); 88 | Snormal_fft = Snormal_fft(1:Nsamps/2); %Discard Half of Points 89 | 90 | figure 91 | plot(f, Snormal_fft) 92 | xlabel('Frequency (Hz)') 93 | ylabel('Amplitude') 94 | title('Frequency Response of Snormal Signal') 95 | 96 | %Filtered 97 | Sfilter_fft = abs(fft(Sfilter)); 98 | Sfilter_fft = Sfilter_fft(1:Nsamps/2); %Discard Half of Points 99 | 100 | figure 101 | plot(f, Sfilter_fft) 102 | xlabel('Frequency (Hz)') 103 | ylabel('Amplitude') 104 | title('Frequency Response of Sfilter') 105 | end 106 | %% Upsampling 107 | % Shift the whole spectrum of Sfilter into inaudible frequency range, 108 | % the maximum ultrasound frequency should be no less than 28kHz 109 | % Upsample the Sfilter 110 | % needs to be upsampled to support ultrawave frequency 192 111 | % KhZ fine, for 30kHz + 2KhZ transition =32KhZ frequency support, 112 | % 64K sampling rate needed, 192 KhZ is perfect. 113 | 114 | Sup = interp(Sfilter,4); 115 | 116 | if ( plotMode == 1) 117 | figure(1) 118 | subplot 212 119 | stem(0:1200,Sup(1:1201),'filled','markersize',3) 120 | grid on 121 | xlabel 'Sample number:192000',ylabel Interpolated 122 | end 123 | 124 | %Upsampled 125 | 126 | Fs_up = Fs * 4; 127 | Nsamps = tmax*Fs_up; 128 | t_up = 1/Fs_up:1/Fs_up:tmax; 129 | f_up = Fs_up*(0:Nsamps/2-1)/Nsamps; %Prepare freq data for plot 130 | 131 | Sup_fft = abs(fft(Sup)); 132 | Sup_fft = Sup_fft(1:Nsamps/2); %Discard Half of Points 133 | if ( plotMode == 1 ) 134 | figure 135 | plot(f_up, Sup_fft) 136 | xlabel('Frequency (Hz)') 137 | ylabel('Amplitude') 138 | title('Frequency Response of Sup') 139 | end 140 | 141 | 142 | %% Ultrasound Modulation 143 | % In this step, we need to shift the spectrum of Sup into high frequency 144 | % range to be inaudible. Here, we adopt amplitude modula- tion for spectrum 145 | %shifting. Assuming the carrier frequency is fc , the modulation can be 146 | %expressed as-> Smodu =n1Sup cos(2?fct) 147 | % where n1 is the normalized coefficient. The resulting modulated signal 148 | %contains two sidebands around the carrier frequency, ranging from 149 | %fc - 8kHz to fc + 8kHz. 150 | %Therefore, fc should be at least 28kHz to be inaudible. 151 | 152 | %fc = carrier frequency; 153 | %Smodu =n1 * Sup * cos(2*pi*fc); 154 | %n1 %normalized coefficient, input argument to function 155 | fc = 30e3; 156 | fs = Fs * 4; 157 | [Smodu,t_modu] = modulate(Sup,fc,fs,'am'); 158 | Smodu = n1 * Smodu; 159 | 160 | Smodu_fft = abs(fft(Smodu)); 161 | Smodu_fft = Smodu_fft(1:Nsamps/2); %Discard Half of Points 162 | 163 | if( plotMode == 1) 164 | figure 165 | plot(f_up, Smodu_fft) 166 | xlabel('Frequency (Hz)') 167 | ylabel('Amplitude') 168 | title('Frequency Response of Smodu') 169 | end 170 | 171 | %% Carrier Wave Addition 172 | 173 | % Modulating the voice spectrum into inaudible frequency range is not enough, 174 | % they have to be translated back to normal voice fre- quency range at the 175 | % microphone for successful attacks. Without modifying the microphone, 176 | % we can leverage its non-linear phenom- enon to achieve demodulation by 177 | % adding a suitable carrier wave, and the final attack ultrasound can be 178 | % expressed as-> 179 | % Sattack =n2(Smodu +cos(2?fct)) 180 | % where n2 is used for signal normalization 181 | 182 | %n2 %normalized signal coefficient, input to function 183 | Sattack = n2 * ( Smodu + cos(2*pi*fc*t_modu) ); 184 | 185 | Sattack_fft = abs(fft(Sattack)); 186 | Sattack_fft = Sattack_fft(1:Nsamps/2); %Discard Half of Points 187 | 188 | if ( plotMode == 1 ) 189 | figure 190 | plot(f_up, Sattack_fft) 191 | xlabel('Frequency (Hz)') 192 | ylabel('Amplitude') 193 | title('Frequency Response of Sattack') 194 | 195 | figure 196 | plot(t_modu,Sattack) 197 | xlabel('sec') 198 | ylabel('Amp') 199 | title('Time domain Sattack') 200 | 201 | figure 202 | spectrogram(Sattack,128,120,128,2e5,'yaxis') 203 | 204 | end 205 | % filename = 'Alexa.m4a'; 206 | % audiowrite(filename,Snormal,Fs) 207 | filename = outputFile; 208 | audiowrite(filename,Sattack,Fs_up) 209 | 210 | %sound(Sfilter,Fs,16); 211 | %sound(Sup,Fs_up,16); 212 | %sound(Sattack,Fs_up,16); 213 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DolphinAttack 2 | 3 | Alexa.m4a is an audio file that contains Alexa command with my terrible voice. 4 | 5 | Running Dolphin.m is a function which I call inside RunDolphin.m. 6 | Input parameters are explained inside script. 7 | 8 | Papers: 9 | 10 | https://arxiv.org/pdf/1708.09537.pdf 11 | https://arxiv.org/pdf/1708.07238.pdf 12 | 13 | ## Logistic Regression Model: 14 | SupervisedLearning.ipynb 15 | 16 | -------------------------------------------------------------------------------- /RecordAttacks/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /RecordAttacks/.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /RecordAttacks/.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /RecordAttacks/.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /RecordAttacks/.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /RecordAttacks/README.md: -------------------------------------------------------------------------------- 1 | # Android app to record voice commands 2 | 3 | Android app to launch Google Voice Recognition API and save recognized voice attacks in *.amr* format. 4 | -------------------------------------------------------------------------------- /RecordAttacks/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /RecordAttacks/app/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # For more information about using CMake with Android Studio, read the 2 | # documentation: https://d.android.com/studio/projects/add-native-code.html 3 | 4 | # Sets the minimum version of CMake required to build the native library. 5 | 6 | cmake_minimum_required(VERSION 3.4.1) 7 | 8 | # Creates and names a library, sets it as either STATIC 9 | # or SHARED, and provides the relative paths to its source code. 10 | # You can define multiple libraries, and CMake builds them for you. 11 | # Gradle automatically packages shared libraries with your APK. 12 | 13 | add_library( # Sets the name of the library. 14 | native-lib 15 | 16 | # Sets the library as a shared library. 17 | SHARED 18 | 19 | # Provides a relative path to your source file(s). 20 | src/main/cpp/native-lib.cpp ) 21 | 22 | # Searches for a specified prebuilt library and stores the path as a 23 | # variable. Because CMake includes system libraries in the search path by 24 | # default, you only need to specify the name of the public NDK library 25 | # you want to add. CMake verifies that the library exists before 26 | # completing its build. 27 | 28 | find_library( # Sets the name of the path variable. 29 | log-lib 30 | 31 | # Specifies the name of the NDK library that 32 | # you want CMake to locate. 33 | log ) 34 | 35 | # Specifies libraries CMake should link to your target library. You 36 | # can link multiple libraries, such as libraries you define in this 37 | # build script, prebuilt third-party libraries, or system libraries. 38 | 39 | target_link_libraries( # Specifies the target library. 40 | native-lib 41 | 42 | # Links the target library to the log library 43 | # included in the NDK. 44 | ${log-lib} ) -------------------------------------------------------------------------------- /RecordAttacks/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | defaultConfig { 6 | applicationId "com.example.skhad.recordattacks" 7 | minSdkVersion 23 8 | targetSdkVersion 26 9 | versionCode 1 10 | versionName "1.0" 11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 12 | externalNativeBuild { 13 | cmake { 14 | cppFlags "-frtti -fexceptions" 15 | } 16 | } 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | externalNativeBuild { 25 | cmake { 26 | path "CMakeLists.txt" 27 | } 28 | } 29 | } 30 | 31 | dependencies { 32 | implementation fileTree(dir: 'libs', include: ['*.jar']) 33 | implementation 'com.android.support:appcompat-v7:26.1.0' 34 | implementation 'com.android.support.constraint:constraint-layout:1.0.2' 35 | testImplementation 'junit:junit:4.12' 36 | androidTestImplementation 'com.android.support.test:runner:1.0.1' 37 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' 38 | } 39 | -------------------------------------------------------------------------------- /RecordAttacks/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /RecordAttacks/app/src/androidTest/java/com/example/skhad/recordattacks/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.skhad.recordattacks; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumented test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.example.skhad.recordattacks", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /RecordAttacks/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /RecordAttacks/app/src/main/cpp/native-lib.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern "C" 5 | JNIEXPORT jstring 6 | 7 | JNICALL 8 | Java_com_example_skhad_recordattacks_MainActivity_stringFromJNI( 9 | JNIEnv *env, 10 | jobject /* this */) { 11 | std::string hello = "Hello from C++"; 12 | return env->NewStringUTF(hello.c_str()); 13 | } 14 | -------------------------------------------------------------------------------- /RecordAttacks/app/src/main/java/com/example/skhad/recordattacks/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.skhad.recordattacks; 2 | 3 | import android.content.ActivityNotFoundException; 4 | import android.content.ContentResolver; 5 | import android.net.rtp.AudioStream; 6 | import android.support.annotation.NonNull; 7 | import android.support.v4.app.ActivityCompat; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.os.Bundle; 10 | import android.util.Log; 11 | import android.widget.Button; 12 | import android.widget.TextView; 13 | import android.widget.ImageButton; 14 | import android.view.View; 15 | import android.content.Intent; 16 | import android.speech.RecognizerIntent; 17 | 18 | import java.io.File; 19 | import java.lang.Object; 20 | import java.text.SimpleDateFormat; 21 | import java.util.Date; 22 | 23 | import java.io.FileNotFoundException; 24 | import java.io.FileOutputStream; 25 | import java.io.IOException; 26 | import java.io.InputStream; 27 | import java.io.DataInputStream; 28 | import java.io.OutputStream; 29 | import java.net.SocketException; 30 | import java.util.Locale; 31 | import java.util.ArrayList; 32 | import android.media.MediaPlayer; 33 | import android.media.MediaRecorder; 34 | import android.Manifest; 35 | import android.content.pm.PackageManager; 36 | import android.widget.Toast; 37 | import android.net.Uri; 38 | 39 | 40 | public class MainActivity extends AppCompatActivity { 41 | 42 | private static final String LOG_SPEECH="Audio2Speech"; 43 | private TextView txtSpeechInput; 44 | private ImageButton btnSpeak; 45 | private Button at_btn; 46 | private Button not_at_btn; 47 | private final int REQ_CODE_SPEECH_INPUT = 100; 48 | 49 | /*fOR AUDIO*/ 50 | private static final String LOG_TAG_AUDIO = "AudioRecordTest"; 51 | private static final int REQUEST_RECORD_AUDIO_PERMISSION = 200; 52 | private static String mFileName = null; 53 | private static String command = null; 54 | private static Uri audioUri = null; 55 | //private RecordButton mRecordButton = null; 56 | private MediaRecorder mRecorder = null; 57 | private ImageButton mPlayButton = null; 58 | private MediaPlayer mPlayer = null; 59 | private static boolean mStartPlaying = true; 60 | 61 | // Requesting permission to RECORD_AUDIO 62 | private boolean permissionToRecordAccepted = false; 63 | private String [] permissions = {Manifest.permission.RECORD_AUDIO}; 64 | 65 | @Override 66 | public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { 67 | super.onRequestPermissionsResult(requestCode, permissions, grantResults); 68 | switch (requestCode){ 69 | case REQUEST_RECORD_AUDIO_PERMISSION: 70 | permissionToRecordAccepted = grantResults[0] == PackageManager.PERMISSION_GRANTED; 71 | break; 72 | } 73 | if (!permissionToRecordAccepted ) finish(); 74 | 75 | } 76 | 77 | 78 | // Used to load the 'native-lib' library on application startup. 79 | static { 80 | System.loadLibrary("native-lib"); 81 | } 82 | 83 | public void saveAttack(boolean attack) { 84 | String atk; 85 | if (attack) atk="attack_"; 86 | else atk = "not_attack_"; 87 | String timeStamp = new SimpleDateFormat("_YYYY-MM-dd_HH:mm:ss_").format(new Date()); 88 | System.out.println("getFilesDir(): " + getFilesDir()); 89 | if (audioUri!= null) { 90 | /*Save sample in attack folder*/ 91 | System.out.println(audioUri.getPath()); 92 | try { 93 | InputStream input = getContentResolver().openInputStream(audioUri); 94 | try { 95 | File file = new File(mFileName, atk+command+"_"+timeStamp+".amr"); 96 | OutputStream output = new FileOutputStream(file); 97 | try { 98 | byte[] buffer = new byte[4 * 1024]; // or other buffer size 99 | int read; 100 | 101 | try { 102 | while ((read = input.read(buffer)) != -1) { 103 | output.write(buffer, 0, read); 104 | } 105 | } catch (IOException e) { 106 | e.printStackTrace(); 107 | } 108 | 109 | try { 110 | output.flush(); 111 | } catch (IOException e) { 112 | e.printStackTrace(); 113 | } 114 | } finally { 115 | try { 116 | output.close(); 117 | } catch (IOException e) { 118 | e.printStackTrace(); 119 | } 120 | } 121 | } finally { 122 | input.close(); 123 | } 124 | System.out.println("Saved audio"); 125 | } catch ( IOException a) { 126 | Log.e(LOG_TAG_AUDIO, "audioURI not found"); 127 | } 128 | } 129 | } 130 | @Override 131 | protected void onCreate(Bundle savedInstanceState) { 132 | super.onCreate(savedInstanceState); 133 | setContentView(R.layout.activity_main); 134 | 135 | // Example of a call to a native method 136 | //TextView tv = (TextView) findViewById(R.id.sample_text); 137 | //tv.setText(stringFromJNI()); 138 | 139 | //super.onCreate(savedInstanceState); 140 | //setContentView(R.layout.activity_main); 141 | 142 | txtSpeechInput = (TextView) findViewById(R.id.command); 143 | btnSpeak = (ImageButton) findViewById(R.id.mic); 144 | at_btn = (Button) findViewById(R.id.attack_btn); 145 | not_at_btn = (Button) findViewById(R.id.not_attack_btn); 146 | 147 | /*Start speech recognizer/audio recorder*/ 148 | btnSpeak.setOnClickListener(new View.OnClickListener() { 149 | @Override 150 | public void onClick(View v) { 151 | promptSpeechInput(); 152 | Log.i(LOG_SPEECH, "PromptSpeech Done.."); 153 | } 154 | }); 155 | 156 | /*Save audio sample into respective folder*/ 157 | at_btn.setOnClickListener(new View.OnClickListener() { 158 | @Override 159 | public void onClick(View v) { 160 | /*Save audio as attack sample*/ 161 | saveAttack(true); 162 | } 163 | }); 164 | not_at_btn.setOnClickListener(new View.OnClickListener() { 165 | @Override 166 | public void onClick(View v) { 167 | /*Save audio as not_attack sample*/ 168 | saveAttack(false); 169 | } 170 | }); 171 | 172 | 173 | // hide the action bar 174 | //getActionBar().hide(); 175 | 176 | /*Initialize audio recording stuff*/ 177 | mFileName = getExternalCacheDir().getAbsolutePath(); 178 | //mFileName += "/audiorecordtest.3gp"; 179 | mPlayButton = (ImageButton) findViewById(R.id.play_btn); 180 | ActivityCompat.requestPermissions(this, permissions, REQUEST_RECORD_AUDIO_PERMISSION); 181 | 182 | mPlayButton.setOnClickListener(new View.OnClickListener() { 183 | @Override 184 | public void onClick(View v) { 185 | System.out.println("OnPlay starting.."); 186 | onPlay(mStartPlaying); 187 | //System.out.println("OnPlay stopped"); 188 | mStartPlaying = !mStartPlaying; 189 | } 190 | }); 191 | } 192 | 193 | /** 194 | * A native method that is implemented by the 'native-lib' native library, 195 | * which is packaged with this application. 196 | */ 197 | public native String stringFromJNI(); 198 | 199 | /*Display google speech input*/ 200 | private void promptSpeechInput() { 201 | Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 202 | intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, 203 | RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 204 | intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault()); 205 | //intent.putExtra(RecognizerIntent.EXTRA_PROMPT, 206 | // getString(R.string.speech_prompt)); 207 | intent.putExtra("android.speech.extra.GET_AUDIO_FORMAT", "audio/AMR"); 208 | intent.putExtra("android.speech.extra.GET_AUDIO", true); 209 | //Start the speech--> Text activity 210 | 211 | try { 212 | //onRecord(true); 213 | startActivityForResult(intent, REQ_CODE_SPEECH_INPUT); 214 | //onRecord(false); 215 | } catch (ActivityNotFoundException a) { 216 | Toast.makeText(getApplicationContext(), 217 | getString(R.string.speech_not_supported), 218 | Toast.LENGTH_SHORT).show(); 219 | } 220 | } 221 | 222 | /* Receiving speech input */ 223 | @Override 224 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 225 | super.onActivityResult(requestCode, resultCode, data); 226 | 227 | switch (requestCode) { 228 | case REQ_CODE_SPEECH_INPUT: { 229 | if (resultCode == RESULT_OK && null != data) { 230 | /*Get string spoken*/ 231 | ArrayList result = data 232 | .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); 233 | txtSpeechInput.setText(result.get(0)); 234 | 235 | /*Set filename to save audio*/ 236 | command = result.get(0); 237 | 238 | /*What's in the bundle?*/ 239 | Bundle bundle = data.getExtras(); 240 | if (bundle != null) { 241 | System.out.println("Printing all the stuff in te bundle.."); 242 | for (String key : bundle.keySet()) { 243 | Object value = bundle.get(key); 244 | System.out.println(String.format("%s %s (%s)", key, 245 | value.toString(), value.getClass().getName())); 246 | } 247 | } 248 | 249 | /*Get audio spoken*/ 250 | audioUri = data.getData(); 251 | System.out.println("Audio: "+audioUri); 252 | /*mPlayer = new MediaPlayer(); 253 | try { 254 | System.out.println("Setting audio source"); 255 | mPlayer.setDataSource(getApplicationContext(), audioUri); 256 | System.out.println("Preparing audio source"); 257 | mPlayer.prepare(); 258 | System.out.println("Starting audio source"); 259 | mPlayer.start(); 260 | System.out.println("Audio source DONE STARTING"); 261 | } catch (IOException e) { 262 | Log.e(LOG_TAG_AUDIO, "prepare() failed"); 263 | } 264 | System.out.println("Releasing audio source"); 265 | mPlayer.release(); 266 | System.out.println("Audio source RELEASED!!"); 267 | mPlayer = null;*/ 268 | } 269 | break; 270 | } 271 | 272 | } 273 | } 274 | 275 | /* 276 | Audio Recording stuff.... 277 | * */ 278 | 279 | 280 | /*pLAY*/ 281 | private void onPlay(boolean start) { 282 | //startPlaying(); 283 | if (start) { 284 | startPlaying(); 285 | } else { 286 | stopPlaying(); 287 | } 288 | } 289 | 290 | private void startPlaying() { 291 | /*Start playing*/ 292 | mPlayer = new MediaPlayer(); 293 | try { 294 | mPlayer.setDataSource(getApplicationContext(), audioUri); 295 | mPlayer.prepare(); 296 | mPlayer.start(); 297 | } catch (IOException e) { 298 | Log.e(LOG_TAG_AUDIO, "prepare() failed"); 299 | } 300 | /*Release the player*/ 301 | //mPlayer.release(); 302 | //mPlayer = null; 303 | } 304 | 305 | private void stopPlaying() { 306 | mPlayer.release(); 307 | mPlayer = null; 308 | } 309 | 310 | 311 | 312 | } 313 | -------------------------------------------------------------------------------- /RecordAttacks/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /RecordAttacks/app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /RecordAttacks/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 18 | 19 |