Esempio n. 1
0
def changeAudio(file_path, sample):
    access_token = '02UMSGJJclAaCjsV2JhZn2cVfRiFTo4NBlQtKycPT6k5IxaGNumOSU7a33Bc-uaGXjnXKbo8y1IaVjMHOchz6ua68Lb7U'

    # Create client with your access token
    client = apiclient.RevAiAPIClient(access_token)

    file_job = client.submit_job_local_file(
        filename=file_path,
        metadata="This_is_some_job_metadata",
        callback_url="",
        skip_diarization=False)

    job_id = file_job.id

    while file_job.status == JobStatus.IN_PROGRESS:
        file_job = client.get_job_details(job_id)
    mylist = []
    file = client.get_transcript_json(job_id)

    end_time = 0.0

    for i in file['monologues']:
        for j in i['elements']:
            if j['type'] == "text":
                if j["value"] == sample:
                    new_tuple = (j["ts"], j["end_ts"])
                    mylist.append(new_tuple)
                end_time = j["end_ts"]

    print(end_time)
    mergetwoaudio(mylist, end_time)
Esempio n. 2
0
def get_transcript(audio_fpath):
    client = apiclient.RevAiAPIClient(
        "023nGm1xNAOR_e8BecAb-8UNWoHzpqh-xBOOgr85kiy1f3y95NYZLo_r634vB8GDBGhlPBhqX7Am-4Mu6-WUcRWtqSfU4"
    )
    job = client.submit_job_local_file(os.path.realpath(audio_fpath))
    job_id = client.get_job_details(job.id)
    time.sleep(2)
    attempts = 20
    for i in range(attempts):
        try:
            transcript_text = client.get_transcript_text(job.id)
            return transcript_text
        except:
            time.sleep(1)
    else:
        return "Operation timed out"
Esempio n. 3
0
def upload(request):

    if request.method == 'GET':  ## For default view
        return render(request, 'upload.html')
    elif request.method == 'POST':

        uploadedFile = request.FILES['file']
        fileName = "static/videos/" + uploadedFile.name

        # Write File mp4
        with open(fileName, "wb") as f:
            for chunk in uploadedFile.chunks():
                f.write(chunk)

        # Convert to mp3
        mp3fileName = fileName[:-4] + ".mp3"
        clip = mp.VideoFileClip(fileName).subclip(0)
        mp3fileNameNoFolder = uploadedFile.name[:-4] + ".mp3"
        clip.audio.write_audiofile(mp3fileName)
        # rev_ai  request

        # Create client with your access token
        client = apiclient.RevAiAPIClient(settings.REV_ACCESS_TOKEN)
        callback_url = "http://35.239.24.77/vidhub/apis/revai/"
        # Submit from local file
        file_job = client.submit_job_local_file(
            filename=mp3fileName,
            callback_url=callback_url,
            metadata="This_is_some_job_metadata",
            skip_diarization=False)

        video_url = "http://35.239.24.77/static/videos/" + uploadedFile.name

        video = Video.objects.create(title=request.POST['title'],
                                     author=request.POST['author'],
                                     video_url=video_url,
                                     rev_id=file_job.id,
                                     subtitle_url='')

        return render(request, 'uploaded.html', {'id': video.id})
    else:
        return HttpResponse("WTF")
Esempio n. 4
0
def transcriber(recording_path):
    client = apiclient.RevAiAPIClient(accesscode)

    # you can send a local file
    job = client.submit_job_local_file(recording_path)

    while True:

        # Obtains details of a job in json format
        job_details = client.get_job_details(job.id)
        status = job_details.status.name

        print("Job Status : {}".format(status))

        # Checks if the job has been transcribed
        if status == "IN_PROGRESS":
            time.sleep(5)
            continue

        elif status == "FAILED":
            print("Job Failed : {}".format(job_details.failure_detail))
            break

        if status == "TRANSCRIBED":
            # Getting a list of current jobs connected with your account
            # The optional parameters limits limits the length of the list. Starting_after
            # Cuts off the beginning x jobs off the list returned
            list_of_jobs = client.get_list_of_jobs(limit=None,
                                                   starting_after=None)

            # obtain transcript text as a string for the job.
            transcript_text = client.get_transcript_text(job.id)
            print(transcript_text)

            # Write to txt file
            f = open("transcript.txt", "w+")
            f.write(transcript_text)
            f.close()

            break
Esempio n. 5
0
def revai_callback(request):
    json_result = (request.body).decode("utf-8")
    print(json_result)
    job = json.loads(json_result)['job']
    print(job)
    video = Video.objects.get(rev_id=job['id'])
    if job['status'] == 'transcribed':

        # Create client with your access token
        client = apiclient.RevAiAPIClient(settings.REV_ACCESS_TOKEN)
        fileName = "static/videos/" + job['name'][:-4] + ".vtt"
        caption = client.get_captions(job['id'], CaptionType.VTT)
        with open(fileName, "w") as f:
            f.write(caption)
        # TRanslate caption
        content_list = caption.splitlines()
        print(content_list)
        client = translate.Client(target_language="th")  ## client  to Google
        for i in range(4, len(content_list), 4):
            print("Send:", content_list[i])
            returnDict = client.translate(content_list[i])
            print("Return:", returnDict)
            returnString = returnDict['translatedText']
            content_list[i] = returnString
        thaifileName = "static/videos/" + job['name'][:-4] + ".vtt.th"
        with open(thaifileName, "w") as f:
            for line in content_list:
                f.write(line + "\n")

        video.subtitle_url = 'http://35.239.24.77/' + fileName

        video.save()
    else:
        video.subtitle_url = 'failed'
        video.save()
    return HttpResponse("Callback received.")
Esempio n. 6
0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

import time
from rev_ai import apiclient

# String containing your access token
access_token = "your_access_token"

# Create your api client
client = apiclient.RevAiAPIClient(access_token)

# Submitting a job through a local file. The optional parameters are shown below.
# job = client.submit_job_local_file("your_local_file_path",
#                                    metadata=None,
#                                    callback_url=None,
#                                    skip_diarization=False,
#                                    custom_vocabularies=None)

# Submitting a job with a link to the file you want transcribed
# Change url to your url
url = "https://www.rev.ai/FTC_Sample_1.mp3"
job = client.submit_job_url(url,
                            metadata=None,
                            callback_url=None,
                            skip_diarization=False,
Esempio n. 7
0
from rev_ai import apiclient
import json
import time
import os
import datetime

client = apiclient.RevAiAPIClient(
    "02-SktQcq_WILkfcQ4ZFPC0A7B0jy57Mdef1Y1dv6I7dB-C_BQGduPIR03QxNomQVjX5nOt0uap-Zn35qDpDUcjwPN1_k")


def convertTime(t):
    return str(datetime.timedelta(seconds=t))


def S2T(audioFile):
    print("Sending ", audioFile, " for speech2text")
    job = client.submit_job_local_file(audioFile)
    id = job.id

    # id = "NIva4qKmLUt1"
    # id = "5xprc0oRG1id"

    # job_details = client.get_job_details(id)

    while True:
        time.sleep(2)
        print("Trying to fetch speech2text output")
        job_details = client.get_job_details(id)
        if str(job_details.status) == "JobStatus.TRANSCRIBED":
            print("Ready, reading json, txt, Txt  files")
            speech = client.get_transcript_text(id)
Esempio n. 8
0
 def __init__(self):
     # create your client
     self.client = apiclient.RevAiAPIClient(ACCESS_TOKEN)
def getname(list, dict):
    for i in list:
        if i in dict:
            print (i + ":" + dict[i][0])
            #image = Image.open(dict[i][1])
            #image = image.resize((240, 320))
            #disp.display(image)
            Image.open(dict[i][1]).show()
        elif i[0:len(i)-1] in dict:
            print (i[0:len(i)-1] + ":" + dict[i[0:len(i)-1]][0])
            Image.open(dict[i[0:len(i)-1]][1]).show()

#Access Token: 02a5E3uxq-KgH_z07nuWDriS-CI8mDsK5whI1DFcel6r5jfjOeSyKSKmjhXgsy7oEYezKicH5VUZW8S1PyhqAj9Fqn4TE
# create your client
client = apiclient.RevAiAPIClient("02a5E3uxq-KgH_z07nuWDriS-CI8mDsK5whI1DFcel6r5jfjOeSyKSKmjhXgsy7oEYezKicH5VUZW8S1PyhqAj9Fqn4TE")

def transcribe(location):
    job = client.submit_job_local_file(location)
    
    job_details = client.get_job_details(job.id)
    status = job_details.status.name
    i = 0
    
    while status != "TRANSCRIBED":
        job_details = client.get_job_details(job.id)
        status = job_details.status.name
        print(status, "         Time to complete:",i,"s")
        i+=1
        time.sleep(1)
    
Esempio n. 10
0
                        '--file',
                        required=True,
                        help='The name of the .mp3 file to convert to text')
    return parser.parse_args().file


if __name__ == "__main__":
    # Get the desired audio file from cmd line
    filename = get_file_name()
    if '.mp3' not in filename:
        print("Error: file type is not mp3")
        sys.exit()

    # Create client with given access token
    client = apiclient.RevAiAPIClient(
        "028f4jLg6e4JCROQXE8vVZbkDlf_5oSfzH-HWyn1ehu6yOiTrVKtwtvLYnVzZZTAayHlalZFqD0zsKajkhYKjO7p8L37k"
    )

    # Create a job to translate a given mp3 file
    job = client.submit_job_local_file(filename)

    # Check if the job is done transcribing
    while True:
        # Obtains details of a job in json format
        job_details = client.get_job_details(job.id)
        status = job_details.status.name

        print("Job Status : {}".format(status))

        # Checks if the job has been transcribed
        if status == "IN_PROGRESS":
Esempio n. 11
0
from rev_ai import apiclient
import sounddevice as sd  # python -m pip install sounddevice --user
from scipy.io.wavfile import write  # pip install scipy
from pydub import AudioSegment  # convert WAV to mp3

rev_ai_token = "02g01w-kZhbjrtz5qXsiT71gchuHv7SyFFqnRTOAjYYTrJlxV7KA9DkYehOZofxVvOZl_qfQD10LlsiMsu6G--WT7ai2I"
client = apiclient.RevAiAPIClient(rev_ai_token)

SentithinkAPI = "[[AZURE WEB API ENDPOINT]]"
Sentithink_auth = "code=[[AUTH TOKEN]]"

x = float(input("Enter microphone X location: "))
y = float(input("Enter microphone Y location: "))
name = input("Enter microphone name: ")

# Capture the sound snippet and save it to file here
frameRate = 44100  # Sample rate
seconds = 10  # Duration of recording

myrecording = sd.rec(int(seconds * frameRate),
                     samplerate=frameRate,
                     channels=2)
sd.wait()  # Wait until recording is finished
write('voiceRecord.wav', frameRate, myrecording)  # Save as WAV file
convertedAudio = AudioSegment.from_wav('voiceRecord.wav')

convertedAudio.export('voiceRecord.mp3', format='mp3')

rev_ai_callback_url = SentithinkAPI + Sentithink_auth + "&X=" + str(
    x) + "&Y=" + str(y) + "&name=" + name
job = client.submit_job_local_file(
Esempio n. 12
0
from rev_ai import apiclient

# create your client
client = apiclient.RevAiAPIClient("02kiXlheeVr0xkYA-oZTevxPeuEWjwVGtyogDlUHyfqmIgFMtR4eX8etW2qyBGTyAoBfjrY6uPBIgZmLuyA4F0nf_g5Hc")
# you can send a local file
job = client.submit_job_local_file("recording.wav")
job_details = client.get_job_details(job.id)
print(repr(job_details), job.id)

# transcript_text = client.get_transcript_text(job.id)
# print(transcript_text)
# client.delete_job(job.id)

Esempio n. 13
0
def getRevAiAPIClient():
	configFileContents = getConfigFileContent()
	ACCESS_TOKEN = configFileContents["rev-ai-access-token"]
	return api.RevAiAPIClient(ACCESS_TOKEN)
from rev_ai import apiclient, JobStatus

API_TOKEN = 'SET_ACCESS_TOKEN_HERE'
REV_CLIENT = apiclient.RevAiAPIClient(API_TOKEN)

from glob import glob
from tqdm import tqdm
from time import sleep
import sys, os
from os.path import basename, isfile


def schedule_jobs(audio_files):
    fid2jid = {}
    for audio_file in tqdm(audio_files, desc='Scheduling jobs'):
        file_id = basename(audio_file).replace('.wav', '')
        job = REV_CLIENT.submit_job_local_file(audio_file)
        if job.status == JobStatus.FAILED:
            print('Job Schedule failed for:', audio_file)
            continue
        fid2jid[file_id] = job.id
    return fid2jid


def libri_transcribe(audio_folder, output_folder, samples_per_batch=100):
    os.makedirs(output_folder, exist_ok=True)
    audio_files = sorted(glob(os.path.join(audio_folder, '*.wav')))
    total_batches = (len(audio_files) + samples_per_batch -
                     1) / samples_per_batch
    i = 0
    while i < len(audio_files):
Esempio n. 15
0
from rev_ai import apiclient
import time
from apihelper import *
# create your client
client = apiclient.RevAiAPIClient(key)
job = client.submit_job_local_file("./recording.m4a")
jobs = client.get_list_of_jobs()
time.sleep(35)
transcript_text = client.get_transcript_text(job.id)
print(transcript_text)