Exemplo n.º 1
0
def transcribe(file):
    prepareFile = file.split("-")
    if (prepareFile[2] in ['mp3', 'wav', 'm4a']):
        file_url = "https://cdn.sanity.io/files/{}/{}/{}.{}".format(PROJECT_ID, DATASET, prepareFile[1], prepareFile[2])
        aai = assemblyai.Client(token=ASSEMBLY_TOKEN)
        transcript = aai.transcribe(audio_url=file_url)

        while transcript.status != 'completed':
            print(transcript.status)
            transcript = transcript.get()

        text = transcript.text
        print(text)
        mutations = {
            "mutations": [{
                "patch": {
                    "id": file,
                    "set": {
                        "transcription": {
                            "text": text,
                            "service": "assemblyai"
                        }
                        }
                    }
                }]
            }

        print("Sending transript of {} to Sanity".format(file))
        r = requests.post(mutations_api, data=json.dumps(mutations), headers=auth_header)
        if (r.status_code == 200 and SLACK_WEBHOOK_URL):
            payload = { "text": "File {} was transcribed successfully".format(file) }
            requests.post(SLACK_WEBHOOK_URL, data=json.dumps(payload))
        else:
            payload = { "text": "An error happened when transcribing {}: {}".format(file, r.message) }
            requests.post(SLACK_WEBHOOK_URL, data=json.dumps(payload))
"""
For stereo audio with two speakers on separate channels, you can leverage
enhanced accuracy and formatting by setting speak_count to 2.
"""

import assemblyai

aai = assemblyai.Client()

model = aai.transcribe('example.wav', speaker_count=2)
Exemplo n.º 3
0
from translate import Translator
import assemblyai
import time
from gtts import gTTS
import os

#key for API
aai = assemblyai.Client(token='bbc8f48274684b24944a9ed0ec6056b7')

#Temp Text file
transcript = aai.transcribe(filename='example.txt')
#Audio File to be translated
transcript = aai.transcribe(filename='Mum.mp3')

#takes audio from mp3 file and converts to text
while transcript.status != 'completed':
    transcript = transcript.get()

#adds text to text variable
text = transcript.text

#prints the text
print("English: " + text)
print("\n")


#To Translate text from english to other language
def tran(toTran, lang):
    translator = Translator(From_lang="autodetect", to_lang=lang)
    translation = translator.translate(toTran)
    print(lang + ": " + translation)
Exemplo n.º 4
0
import assemblyai

aai = assemblyai.Client(token=' 11fc9ccf99d040b5a831216a17556e4e')

transcript = aai.transcribe(filename='/home/adhoc/non-coder/aud.wav')


while transcript.status != 'completed':
    transcript = transcript.get()

text = transcript.text





Exemplo n.º 5
0
import subprocess
import assemblyai as aai
import json
import sys
import time
import requests
import summarize

token = 'cc0738780ad94cd29c92750529eb5f5a'
ai = aai.Client(token=token)


def saveAudio(username, video):
    vpath = "Database/Users/" + username + "/Videos/Video " + str(video)
    command = 'ffmpeg -i "Database/Users/' + username + '/Videos/Video ' + str(
        video
    ) + '/video.mp4" -vn -ab 160k -ac 1 -ar 44100 -vn "Database/Users/' + username + '/Videos/Video ' + str(
        video) + '/audio.mp3"'
    subprocess.call(command, shell=True)

    with open(vpath + "/videodetails.json", "r") as readfile:
        vjson = json.load(readfile)
        username = vjson['username']
        videono = vjson['videono']
        title = vjson['title']
        description = vjson['description']
        keywords = vjson['keywords']
        savestatus = vjson['savestatus']
        audiosavedstatus = vjson['audiosavedstatus']
        assemblystatus = vjson['assemblystatus']
        transcriptstatus = vjson['transcriptstatus']
Exemplo n.º 6
0
import json
import requests

import assemblyai

url = 'https://api.assemblyai.com/transcript'
token = None

headers = {'authorization': token}
audio_file = 'f.mp3'

audio_file = 'https://avilpage.com/media/audio/blob_ZzyEsGT'

data = json.dumps({'audio_src_url': audio_file})
r = requests.post(url, data=data, headers=headers)

aai = assemblyai.Client(token=token)
audio_file = 'audio/blob_05Qf5MO'
transcript = aai.transcribe(filename=audio_file)

while transcript.status != 'completed':
    transcript = transcript.get()

text = transcript.text
print(text)
Exemplo n.º 7
0
import sys
import assemblyai
import TextAnalysis as ta

print("Type of cmd line arguments are ", type(sys.argv))
fileName = sys.argv[1]
try:
    aai = assemblyai.Client(token='Your Assembly AI token ID')
    transcript = aai.transcribe(filename=fileName)

    while transcript.status != 'completed':
        transcript = transcript.get()
        text = transcript.text
        print(text)
    text = transcript.text
    print(text)
    ta.Analyze(text)
except ConnectionError:
    print("Error occured, Please check your internet connection.")