def generate_audio_captcha(numbers): """ Function to generate the audio captcha. :param numbers: is what will be generated :return: """ audio = AudioCaptcha() # Store the captcha into a variable image audio.write(numbers, "demo.wav")
def audio(request): global atext if request.method == 'POST': response = request.POST.get("captcha-text") if response == atext: return render(request, 'success.html') else: return render(request, 'audio.html', {'message': 'Try Again'}) captcha_text = str(random.randint(1000, 9999)) audio_captcha = AudioCaptcha() audio_data = audio_captcha.generate(captcha_text) audio_captcha.write(captcha_text, './static/cap.wav') atext = captcha_text return render(request, 'audio.html')
def main(): if len(sys.argv) != 4: print("Usage: {} output_dir length count".format(sys.argv[0])) return output_dir = sys.argv[1] length = int(sys.argv[2]) count = int(sys.argv[3]) if not os.path.exists(output_dir): print("{} does not exist".format(output_dir)) audio = AudioCaptcha(voicedir=os.path.join( os.path.dirname(os.path.realpath(__file__)), "voices_en")) for i in range(count): inp = ''.join(random.choices(CHARSET, k=length)) filename = "{}_{}.wav".format(inp, secrets.token_hex(4)) audio.write(inp, os.path.join(output_dir, filename)) print("Generated: {}".format(filename))
def create_audio_captcha(): # Create the audio captcha with the specified voice wav file library folder. # Each captcha char should has it's own directory under the specified folder ( such as ./voices), # for example ./voices/a/a.wav will be played when the character is a. # If you do not specify your own voice file library folder, the default built-in voice library which has only digital voice file will be used. # audio_captcha = AudioCaptcha(voicedir='./voices') # Create an audio captcha which use digital voice file only. audio_captcha = AudioCaptcha() # Because we use the default module voice library, so we can only generate digital text voice. captcha_text = create_random_digital_text() # Generate the audio captcha file. audio_data = audio_captcha.generate(captcha_text) # Save the autiod captcha file. audio_file = "./captcha_"+captcha_text+'.wav' audio_captcha.write(captcha_text, audio_file) print(audio_file + " has been created.")
def create_audio_and_convert(output_dir, captcha_text): pwd = os.getcwd() work_dir = pwd + '\\symbols\\' #combined_sounds = None #for symbol in captcha_text: #tts_service = random.choice(tts_list) #raw_path = work_dir + tts_service + '\\' + symbol #sound = AudioSegment.from_wav(raw_path + ".wav") #if combined_sounds is None: # combined_sounds = sound #else: # combined_sounds = combined_sounds + sound audio = AudioCaptcha() audio.write(captcha_text, output_dir) if not os.path.exists(pwd + '\\' + tempDir): print("Creating temp directory " + tempDir) os.makedirs(pwd + '\\' + tempDir) output_dir_tts = pwd + '\\' + tempDir + '\\' wav_audio_path = output_dir_tts + captcha_text + '.wav' audio.export(wav_audio_path, format="wav") plt.interactive(False) clip, sample_rate = librosa.load(wav_audio_path, sr=None) fig = plt.figure(figsize=[0.415, 0.210]) ax = fig.add_subplot(111) ax.axes.get_xaxis().set_visible(False) ax.axes.get_yaxis().set_visible(False) ax.set_frame_on(False) S = librosa.feature.melspectrogram(y=clip, sr=sample_rate) librosa.display.specshow(librosa.power_to_db(S, ref=np.max)) filename = os.path.join(output_dir, captcha_text + '.jpg') plt.savefig(filename, dpi=400, bbox_inches='tight', pad_inches=0) plt.close() fig.clf() plt.close(fig) plt.close('all') del clip, sample_rate, fig, ax, S
def create_audio_captcha(): # Create the audio captcha with the specified voice wav file library folder. # Each captcha char should has it's own directory under the specified folder ( such as ./voices), # for example ./voices/a/a.wav will be played when the character is a. # If you do not specify your own voice file library folder, the default built-in voice library which has only digital voice file will be used. # audio_captcha = AudioCaptcha(voicedir='./voices') # Create an audio captcha which use digital voice file only. audio_captcha = AudioCaptcha(voicedir='./voices') #audio_captcha = AudioCaptcha(voicedir='C:\\Users\\SIDDHARTHA\\Dropbox\\Trinity Data Science\\Scalable Computing\\Projects\\audio-alphabet') # Because we use the default module voice library, so we can only generate digital text voice. #captcha_text = create_random_digital_text() captcha_text = "a" # Generate the audio captcha file. audio_data = audio_captcha.generate(captcha_text) # Save the autiod captcha file. audio_file = "./"+captcha_text+'.wav' audio_captcha.write(captcha_text, audio_file) print(audio_file + " has been created.")
from captcha.image import ImageCaptcha #For generating the image captcha image=ImageCaptcha() data=image.generate('DI123') image.write('DI123','captcha.jpg') #For generating the audio captcha from captcha.audio import AudioCaptcha audio=AudioCaptcha() data1=audio.generate("1223") audio.write('1223','1.wav')
from captcha.audio import AudioCaptcha audio = AudioCaptcha('data/') audio.write('1024', 'e:/test.mp3')
# Generate Random Captcha In Python # import required modules from captcha.image import ImageCaptcha from captcha.audio import AudioCaptcha import random # Create an instance of ImageCaptcha. img = ImageCaptcha() # Create an instance of AudioCaptcha. audio = AudioCaptcha() # generate rand string of number rand = str(random.randint(10000, 99999)) # Call img.generate method to create the image object img.generate(rand) # Call img.write method to save the image to a file. img.write(rand, 'cap.png') # Generate autio captcha data audio.generate(rand) # Save the audio captcha data into a audio file. audio.write(rand, 'aud.wav')
from captcha.audio import AudioCaptcha from captcha.image import ImageCaptcha audio = AudioCaptcha(voicedir='/path/to/voices') image = ImageCaptcha(fonts=['/path/A.ttf', '/path/B.ttf']) data = audio.generate('1234') audio.write('1234', 'out.wav') data = image.generate('1234') image.write('1234', 'out.png')
# Developed by: Calinescu Mihai <*****@*****.**> # Date: November 19th, 2021 from captcha.audio import AudioCaptcha user_input = input("Enter text to store as audio (only numbers): ") data = audio.generate(user_input) audio = AudioCaptcha() audio.write(user_input, 'audio/{}.wav'.format(user_input))
def GenerateAudioCaptcha(text, out_path, voicedir=None): audio = AudioCaptcha(voicedir=voicedir) # data = audio.generate(text) audio.write(text, out_path)
# captcha has string and num def get_string(letters_count, digits_count): letters = ''.join( (random.choice(string.ascii_letters) for i in range(letters_count))) digits = ''.join( (random.choice(string.digits) for i in range(digits_count))) # convert resultant string to list and shuffle it to mix letters and digits sample_list = list(letters + digits) random.shuffle(sample_list) # convert list to string final_string = ''.join(sample_list) return final_string myCaptcha = get_string(5, 5) #gen Captcha image = ImageCaptcha(width=280, height=90) audio = AudioCaptcha() data = image.generate(myCaptcha) data = image.generate(myStringCaptcha) data = image.generate(myNumCaptcha) data = audio.generate(myNumCaptcha) image.write(myCaptcha, 'demoCaptcha.png') image.write(myStringCaptcha, 'demoStringCaptcha.png') image.write(myNumCaptcha, 'demoNumCaptcha.png') audio.write(myNumCaptcha, 'demoNumCaptcha.waw')
def do_audio(): audio = AudioCaptcha(voicedir="./") data = audio.generate("1234") assert isinstance(data, bytearray) audio.write("1234", "out.wav")
from captcha.image import ImageCaptcha from captcha.audio import AudioCaptcha ##################### 图片验证码 image = ImageCaptcha(fonts=['almfixed.ttf', 'Arimo-BoldItalic.ttf']) # 添加想要的字体 image.write("FishC", "captcha2.png") # 第一个参数指定要写入的内容,第二个参数是名字 ##################### 音频验证码 audio = AudioCaptcha(voicedir='dog.wav') # 参数指定声音素材 audio.write("dog", 'captcha.wav')
#generate image captcha from captcha.image import ImageCaptcha image = ImageCaptcha() image_data = image.generate('AI SOCIETY') image.write('AI SOCIETY', 'captcha.png') #generate audio captcha from captcha.audio import AudioCaptcha audio = AudioCaptcha() audio_data = audio.generate('45678') audio.write('45678', 'audio.wav')
#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Created on Sun Nov 25 10:50:38 2018 @author: ahaandabholkar """ from captcha.audio import AudioCaptcha from random import randint def random_with_N_digits(n): range_start = 10**(n - 1) range_end = (10**n) - 1 return randint(range_start, range_end) audio = AudioCaptcha() for i in range(100): t = str(random_with_N_digits(4)) audio.write(t, 'init_dataset/' + t + '.wav')
while True: valid = input() if valid == data: print("Captcha Validated") break else: i += 1 if i == tries: print("Failed! The captcha was", data) break print("Wrong input! Try again") # audio captcha nums = randomiseNumbers() audio = AudioCaptcha() audio.write(nums, "out.wav") playsound("out.wav") i = 0 print("Enter the captcha : ") while True: valid = input() if valid == nums: print("Captcha Validated") break else: i += 1 if i == tries: print("Failed! The captcha was", nums) break print("Wrong input! Try again")
from captcha.image import ImageCaptcha from captcha.audio import AudioCaptcha image = ImageCaptcha() image_data = image.generate('Sareer Talks') image.write('Sareer Talks', 'cap.png') audio = AudioCaptcha() audio_data = audio.generate('12345') audio.write('12345', 'audio.mp3')
# Create your own Image and Audio Captcha # For Image Captcha from captcha.image import ImageCaptcha image = ImageCaptcha(width=280, height=90) data = image.generate('github2104klop') image.write('github2104klop', 'create Captcha2.png') # For Audio Captcha from captcha.audio import AudioCaptcha audio = AudioCaptcha() data1 = audio.generate('406') audio.write('406', 'Create Audio Captcha1.wav')
'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' ] smallletterList = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' ] numberList = ['1', '2', '3', '4', '5', '6', '7', '8', '9'] randomthreeBigLetter = random.choices(capitalletterList, k=3) randomtwosmallLetter = random.choices(smallletterList, k=2) randomtwonumber = random.choices(numberList, k=2) listrandom = randomthreeBigLetter + randomtwosmallLetter + randomtwonumber random.shuffle(listrandom) captcha = ("".join(listrandom)) print(f"The Captcha is: {captcha}") image_data = image.generate(captcha) image.write(captcha, 'captcha.png') #generate audio captcha from captcha.audio import AudioCaptcha audio = AudioCaptcha() #this will give 2 random integers randomtwoint = random.choices(numberList, k=2) twoint = ("").join(randomtwoint) print(f"The Audio Captcha is: {twoint}") audio_data = audio.generate(str(twoint)) audio.write(str(twoint), 'audioCaptcha.wav')
def generate_audio_captcha(num): audio = AudioCaptcha() data = audio.generate(num) audio.write(num, 'captcha.wav')
from captcha.image import ImageCaptcha from captcha.audio import AudioCaptcha img = ImageCaptcha() audio = AudioCaptcha() # img.write("xy12", 'xy.png') data = audio.generate('123456789') audio.write('1234', '2.mp3')
data = image.generate("CCCCVGFD") image.write('CCCCVGFD', 'demo2.png') # In[10]: from captcha.image import ImageCaptcha image = ImageCaptcha(width=280, height=90) data = image.generate("BHBHGFFDD") image.write('BHBHGFFDD', 'demo3.png') # In[16]: from captcha.image import ImageCaptcha image = ImageCaptcha(width=270, height=80) data = image.generate("12CCP890") image.write('12CCP890', 'demo4.png') # # Audio Captcha # In[27]: from captcha.audio import AudioCaptcha audio = AudioCaptcha() data = audio.generate("99898") audio.write('99898', 'demo6.wmv') # In[ ]:
#Code By Amey Band from captcha.audio import AudioCaptcha from captcha.image import ImageCaptcha image = ImageCaptcha() data = image.generate('12AFGcvd') image.write('12AFGcvd', 'op.png') audio = AudioCaptcha() data = audio.generate('59647834') audio.write('59647834', 'op.wav')