Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
Calling Async function inside Web Speech API function

I'm trying to get the text from audio using Web Speech API, pass that text to the API call, and display the result with textarea. Each function works fine when called separately. But once I tried to connect them, textarea displays nothing.

<button id="start-recording" onclick="recognition.start()">Start</button>
<textarea id="results"></textarea>
<script type="text/javascript">
      const recognition = new webkitSpeechRecognition();
      const resultpreview = document.getElementById("results");

      recognition.onresult = function (event) {
        if (event.results.length > 0) {
          const text = event.results[0][0].transcript;
          callAPI(text);
        }
      };

      const callAPI = async (text) => {
        var requestJson = {
          access_key: access_key,
          argument: {
            text: text,
            analysis_code: analysisCode,
          },
        };

        const response = await fetch(myURL, {
          method: "POST",
          body: JSON.stringify(requestJson),
          headers: { "Content-Type": "application/json; charset=UTF-8" },
        });

        const myJson = await response.json();
        const words = myJson.return_object.sentence[0].NE;

        for (const word of words) {
          resultpreview.innerHTML += word.text;
        }
      };
</script>
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!