튜토리얼: Node.js를 사용하여 Speech-to-Text API 사용하기

오디오 파일 또는 오디오 스트림을 서면 텍스트로 변환하는 Deepgram의 API로 재생



The purpose of building this blog is to write down the detailed operation history and my memo for learning Node.js.
If you are also interested and want to get hands dirty, just follow these steps below and have fun!~



전제 조건


  • 설치했습니다 Node.js
  • 명령줄 인터페이스(CLI/터미널) 보유
  • 좋아하는 코드 IDE가 있습니다(예: VSCode )
  • Deepgram 계정을 만들었습니다.

  • 시작하기



    먼저 선호하는 디렉토리로 이동하고 다음 명령을 사용하여 폴더(예: sttApp)를 생성해야 합니다.

    mkdir sttApp
    


    그런 다음 좋아하는 IDE를 사용하여 폴더를 엽니다. 내 것은 VS 코드입니다. 이제 디렉토리가 파일 없이 비어 있음을 알 수 있습니다.



    다음 단계에서는 터미널을 사용하여 현재 디렉토리/sttApp으로 이동합니다.

    cd sttApp
    


    그리고 다음 코드를 실행하여 새 애플리케이션을 초기화합니다.

    npm init
    


    Enter 키를 여러 번 눌러 이러한 매개변수를 기본 구성으로 유지하면 CLI에 다음과 같은 결과가 표시됩니다.



    다음으로 다음을 사용하여 Deepgram Node.js SDK를 설치합니다.

    npm install @deepgram/sdk
    




    지금까지 이전 단계가 모두 정확하다면 코드 IDE에서 다음과 같은 유사한 디렉토리를 얻을 수 있습니다.



    이제 코드 IDE(/sttAPP)의 현재 디렉터리에서 index.js 라는 파일을 만들고 다음 코드를 복사하여 index.js에 붙여넣고 파일을 저장합니다.

    const { Deepgram } = require('@deepgram/sdk');
    const fs = require('fs');
    
    // The API key you created in step 1
    const deepgramApiKey = 'YOUR_API_KEY';
    
    // Replace with your file path and audio mimetype
    const pathToFile = 'SOME_FILE.wav';
    const mimetype = 'audio/wav';
    
    // Initializes the Deepgram SDK
    const deepgram = new Deepgram(deepgramApiKey);
    
    console.log('Requesting transcript...')
    console.log('Your file may take up to a couple minutes to process.')
    console.log('While you wait, did you know that Deepgram accepts over 40 audio file formats? Even MP4s.')
    console.log('To learn more about customizing your transcripts check out developers.deepgram.com.')
    
    deepgram.transcription.preRecorded(
      { buffer: fs.readFileSync(pathToFile), mimetype },
      { punctuate: true, language: 'en-US' },
    )
    .then((transcription) => {
      console.dir(transcription, {depth: null});
    })
    .catch((err) => {
      console.log(err);
    });
    




    다음 단계는 Deepgram 에 로그인하고 대시보드로 이동하여 API 또는 SDK를 통해 대본 가져오기를 선택하는 것입니다.



    키 공개를 클릭하고 API KEY SECRET을 복사합니다.





    다음 단계에서 API KEY SECRET을 index.js의 5행에 다음과 같이 붙여넣습니다.



    그런 다음 8번과 9번 줄을 음성 파일 경로와 MIME 형식으로 바꾸겠습니다.
    (힌트: 새 CLI를 사용하여 음성 파일이 있는 디렉토리로 이동하고 pwd를 사용하여 절대 경로를 획득):



    이제 마지막으로 다음 명령을 사용하여 애플리케이션을 실행해 보겠습니다(/sttApp에 ​​있는지 확인).

    node index.js
    


    그리고 원하는 스크립트와 단어 배열, 타이밍, 신뢰도 점수를 포함한 JSON 응답을 받게 됩니다.





    정말 멋진!

    위의 내용이 여전히 혼란스럽다면 아래에 메시지를 남기거나 전체 프로젝트에 대한 내 git 저장소를 참조하십시오. linkToGit

    참고문헌



    https://console.deepgram.com/project/850abca5-449a-47fa-8c40-6a463e59ad00/mission/transcript-via-api-or-sdk

    내 제출 개요



    Deepgram의 STT API를 사용하여 node.js를 배우는 초보자를 위한 튜토리얼입니다.

    제출 카테고리:



    분석 대사

    GitHub의 코드 링크



    linkToGit

    추가 리소스/정보



    없음

    좋은 웹페이지 즐겨찾기