示例#1
0
def main():
    parser = argparse.ArgumentParser(description="Generate and save a given word's speech.")
    parser.add_argument('--word', type=str, default=None, help='Word to be spoken')
    parser.add_argument('--leo_code', type=str, default=None, help='LEO audio code if you really want the audio from there and the script magic is not working. If the --word argument is given, the output name format will be preserved, otherwise you will get a random_leters.mp3 in your folder.')
    parser.add_argument('--lang', type=str, default='de', help='Language that you want your text to be spoken. Until it does not make any difference besides changing the name of the outputted file.')
    parser.add_argument('--force_google', type=bool, default=False, help='It forces using Google Translate engine (useful when LEO fails to work (aka do wrong stuff))')

    args = parser.parse_args()

    if not args.word and not args.leo_code:
        print("--word or --leo_code have to be provided as argument!")
        exit(1)

    if args.leo_code:
        audio = download_audio_leo(audio_code=args.leo_code)
        output_file = output_text(args.word, args.lang) if args.word else args.leo_code
        with open(f'{output_file}.mp3', 'wb') as f:
            f.write(audio.read())

        print("You forced, but i think LEO worked, check it out! :-)")

    # we try first with LEO, if we dont find anything there, then we use google translate
    elif not get_from_leo(args.word, args.lang) or args.force_google:
        print("We are getting from Google Translate anyways... :-(")
        speech = Speech(args.word, args.lang)
        # save the speech to an MP3 file (no effect is applied)
        speech.save(f"{output_text(args.word, args.lang)}.mp3")
    
    else:
        print("Apparently LEO worked, check it out! :-)")
示例#2
0
 def speak(self, text):
     speech = Speech(text, self.language)
     # speech.play(sox_effects=("speed", DEFAULT_SPEED))
     PATH = os.getcwd() + r"\Audio\test.mp3"
     speech.save(PATH)
     # self.play_audio_file(PATH)
     song = AudioSegment.from_mp3(PATH)
     play(song)
示例#3
0
def main():
    parser = argparse.ArgumentParser()

    parser.add_argument('--count',
                        help='How many captchas to generate',
                        type=int)
    parser.add_argument('--output-dir',
                        help='Where to store the generated captchas',
                        type=str)
    parser.add_argument('--symbols',
                        help='File with the symbols to use in captchas',
                        type=str)
    args = parser.parse_args()

    if args.count is None:
        print("Please specify the captcha count to generate")
        exit(1)

    if args.output_dir is None:
        print("Please specify the captcha output directory")
        exit(1)

    if args.symbols is None:
        print("Please specify the captcha symbols file")
        exit(1)

    symbols_file = open(args.symbols, 'r')
    captcha_symbols = symbols_file.readline().strip()
    symbols_file.close()

    print("Generating captchas with symbol set {" + captcha_symbols + "}")

    if not os.path.exists(args.output_dir):
        print("Creating output directory " + args.output_dir)
        os.makedirs(args.output_dir)

    for i in range(args.count):
        captcha_text = ''.join(
            [random.choice(captcha_symbols) for j in range(args.length)])
        #print(captcha_text)
        lang = "en"
        speech = Speech(captcha_text, lang)
        #speech.play()

        #sox_effects = ("speed", "1.5")
        #speech.play(sox_effects)
        image_path = os.path.join(args.output_dir, captcha_text + '.png')
        if os.path.exists(image_path):
            version = 1
            while os.path.exists(
                    os.path.join(args.output_dir,
                                 captcha_text + '_' + str(version) + '.png')):
                version += 1
            image_path = os.path.join(
                args.output_dir, captcha_text + '_' + str(version) + '.png')

        audio_path = os.path.join(args.output_dir, captcha_text + '.mp3')
        speech.save(audio_path)
示例#4
0
def get_gspeech(text: str):
    if not text:
        return
    speech = Speech(text, 'en')
    filename = os.path.join(cachepath, "cache.mp3")
    speech.save(filename)
    with open(filename, 'rb') as f:
        base64_audio = base64.b64encode(f.read())
    return base64_audio
示例#5
0
    def speak_and_save(self, text, path, index):
        speech = Speech(text, self.language)
        speech.play(sox_effects=("speed", DEFAULT_SPEED))

        if not os.path.isdir(path):
            os.mkdir(path)
            pass

        full_path = "{}/{}.mp3".format(path, index)
        print(full_path)
        speech.save(full_path)
示例#6
0
def make_wav(name, template, args):
    output_file = '{0}.mp3'.format(name)
    transcript = template.substitute(args)
    speech = Speech(
        transcript,
        random.choice(['en-UK', 'en-US', 'en-IE', 'en-ZA', 'en-NZ', 'en-KE']))
    speech.save('tmp.mp3')
    pitch = random.choice([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
    subprocess.call([
        'sox', 'tmp.mp3', 'tmp2.wav', 'pitch', '-{}00'.format(pitch), 'speed',
        '1.3'.format(pitch), 'reverse'
    ])
    subprocess.call([
        'sox', 'tmp2.wav', output_file, 'reverse', 'silence', '1', '00:00:01',
        '-96d'
    ])
    return output_file
示例#7
0
文件: main.py 项目: nikneym/Rachael
async def speak_voice_channel(ctx, *, arg):
    voice_channel = ctx.voice_client

    speech = Speech(arg, "tr")
    save_speech = speech.save("deneme.mp3")
    #speech.play()

    voice_channel.play(discord.FFmpegPCMAudio("deneme.mp3"),
                       after=lambda e: print('done', e))
def get_google(filename):

    f = open(filename, "r")
    lines = f.readlines()
    f.close()

    output = []
    counter = 1
    plregex = re.compile("<pl>(.+)</pl>")
    for line in lines:
        line = line.strip()
        match = plregex.search(line)
        # print(match)
        if match:
            text = match.group(1)
            print("polish", text)
            lang = "pl"
            filename = "gspeech/" + str(counter) + ".mp3"
            print("filename", filename)
            speech = Speech(text, lang)
            speech.save(filename)
            time.sleep(0.5)
            counter = counter + 1
示例#9
0
def get_google_speech(opts):
    
    tree = ET.parse(opts.xmlfile)
    root = tree.getroot()
    
    els=root.findall(".//pl")
    
    # print(els)
    
    pattern=re.compile("\((N ?)?[\d]\)")
    elnb=1
    for el in els:
        text=el.text
        lang = "pl"
        ahash = hashlib.md5(text.encode("utf-8")).hexdigest()
        filename="gspeech/"+ahash+".mp3"
        print("filename",filename)
    
        speech = Speech(text, lang)
        speech.save(filename)
        time.sleep(0.5)
        
        elnb=elnb+1
示例#10
0
# pip install google_speech

from google_speech import Speech
import PyPDF2

# ABRIR O ARQUIVO PDF
book = open("oop.pdf", "rb")
pdfReader = PyPDF2.PdfFileReader(book)
pages = pdfReader.numPages
# print(pages)

# OBTER O TEXTO
page = pdfReader.getPage(7)
text = page.extractText().encode("utf-8").decode("utf-8")

# LER O TEXTO
lang = "pt_BR"
speech = Speech(text, lang)
sox_effects = ("speed", "1.06")
# speech.play(sox_effects)

# GRAVAR ARQUIVO
speech.save("Oop.mp3")
示例#11
0
 def save_speech_to(text_to_speech, subfolder, lang):
     speech = Speech(text_to_speech, lang)
     Helper.create_folder_if_not_exist(subfolder)
     path_to_save = subfolder + "\\" + Helper.remove_special_symbols(text_to_speech) + ".mp3"
     speech.save(path_to_save)
     return path_to_save
示例#12
0
from google_speech import Speech

# say "Hello World"
text = "Hello World"
lang = "en"
speech = Speech(text, lang)
speech.play()

# you can also apply audio effects while playing (using SoX)
# see http://sox.sourceforge.net/sox.html#EFFECTS for full effect documentation
# sox_effects = ("speed", "1.5")
# speech.play(sox_effects)

# save the speech to an MP3 file (no effect is applied)
speech.save("output.mp3")
示例#13
0
from google_speech import Speech

lang = "pt_BR"
sox_effects = ("speed", "1.06")

with open("LeiInovacao", "r") as f:
    texto = f.readlines()

textoFim = ""
totLin = 0
numPag = 1

for lin in texto:
    lin = lin.encode("utf-8").decode("utf-8").replace('\n', ' ')
    textoFim += lin
    totLin += 1
    if (totLin == 20):
        speech = Speech(textoFim, lang)
        speech.save("LeiInovacao" + str(numPag) + ".mp3")
        textoFim = ""
        totLin = 0
        numPag += 1

if (totLin > 0):
    speech = Speech(textoFim, lang)
    speech.save("LeiInovacao" + str(numPag) + ".mp3")
示例#14
0
def retrieve_example_audio(exFilePath, text, lang='en'):
    from google_speech import Speech

    speech = Speech(text, lang)
    # save the speech to an MP3 file (no effect is applied)
    speech.save(exFilePath)