Skip to content

Instantly share code, notes, and snippets.

@deepanshu-nickelfox
Forked from harunurkst/asyncio_dj_ex1.py
Created November 10, 2020 04:49
Show Gist options
  • Select an option

  • Save deepanshu-nickelfox/10c35030ff9c9b64658d5aa57d1fdaa6 to your computer and use it in GitHub Desktop.

Select an option

Save deepanshu-nickelfox/10c35030ff9c9b64658d5aa57d1fdaa6 to your computer and use it in GitHub Desktop.

Revisions

  1. @harunurkst harunurkst renamed this gist May 8, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @harunurkst harunurkst created this gist May 8, 2019.
    18 changes: 18 additions & 0 deletions asyncio_ex1.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,18 @@
    def djangoview(request, language1, language2):
    async def main(language1, language2):
    loop = asyncio.get_event_loop()
    r = sr.Recognizer()
    with sr.AudioFile(path.join(os.getcwd(), "audio.wav")) as source:
    audio = r.record(source)
    def reco_ibm(lang):
    return(r.recognize_ibm(audio, key, secret language=lang, show_all=True))
    future1 = loop.run_in_executor(None, reco_ibm, str(language1))
    future2 = loop.run_in_executor(None, reco_ibm, str(language2))
    response1 = await future1
    response2 = await future2
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    loop = asyncio.get_event_loop()
    loop.run_until_complete(main(language1, language2))
    loop.close()
    return(HttpResponse)