コード例 #1
0
ファイル: main.py プロジェクト: Jcellier/CAPTCHA
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")
コード例 #2
0
ファイル: views.py プロジェクト: harmeetsingh01/captchas
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')
コード例 #3
0
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))
コード例 #4
0
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.")
コード例 #5
0
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
コード例 #6
0
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.")
コード例 #7
0
ファイル: captcha.py プロジェクト: Dikshit-Kapoor/ReCaptcha
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')
コード例 #8
0
ファイル: audiocaptcha.py プロジェクト: pandora2333/python
from captcha.audio import AudioCaptcha
audio = AudioCaptcha('data/')
audio.write('1024', 'e:/test.mp3')
コード例 #9
0
# 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')
コード例 #10
0
ファイル: captcha1.py プロジェクト: NerdJain/Python
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')
コード例 #11
0
ファイル: audio.py プロジェクト: CMihai99/python-projects
# 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))
コード例 #12
0
def GenerateAudioCaptcha(text, out_path, voicedir=None):
    audio = AudioCaptcha(voicedir=voicedir)
    # data = audio.generate(text)
    audio.write(text, out_path)
コード例 #13
0
# 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')
コード例 #14
0
ファイル: test2.py プロジェクト: fzh890523/py_sth
def do_audio():
    audio = AudioCaptcha(voicedir="./")

    data = audio.generate("1234")
    assert isinstance(data, bytearray)
    audio.write("1234", "out.wav")
コード例 #15
0
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')
コード例 #16
0
#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')
コード例 #17
0
#!/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')
コード例 #18
0
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")
コード例 #19
0
ファイル: main.py プロジェクト: thisissareer/Captcha
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')
コード例 #20
0
# 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')
コード例 #21
0
ファイル: main.py プロジェクト: sahaj169/Create-captcha
    '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')
コード例 #22
0
def generate_audio_captcha(num):
    audio = AudioCaptcha()
    data = audio.generate(num)
    audio.write(num, 'captcha.wav')
コード例 #23
0
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')
コード例 #24
0
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[ ]:
コード例 #25
0
#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')