'Asynchronous Amazon Transcribe speech2text display transcripts with Django

I'm trying to build a fullstack web app with AWS Transcribe service and Django and Python. What I want to achieve is something like displaying transcripts from speaker in real time word by word.

A demo can be found here: https://www.loom.com/share/f49e8d2b264a4c9b8803a7b0612d103f?t=0 The AWS Transcribe sample code can be found: https://github.com/awslabs/amazon-transcribe-streaming-sdk/blob/develop/examples/simple_mic.py

But I'm having trouble displaying the text line by line. What I can achieve so far is I can allow the user to speak for 10 seconds and then display the whole transcript on a web page.

See my code below:

# Create your views here.
def home(request):
    return render(request, 'aws_transcribe_model/home.html')


def startVideoChat(request):
    t1 = threading.Thread(target=startTranscribing)
    t1.start()
 
    t1.join(10.0)

    print("\n ------------------------------------ \n")
    print("transcribing finished")
    print(CONSTS.transcript)

    return render(request, 'aws_transcribe_model/startvideochat.html', {'transcript': CONSTS.transcript})


def startTranscribing():
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop.run_until_complete(sample_Amazon_Transcribe_simple_mic.basic_transcribe())
    loop.close()

I've been looking into things but have not found a solution how to display the text line by line. As you can see in method startVideoChat I can only return once with the html file. Is there a simple way to do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source