Rails로 통화 내용을 음성 인식
                                            
                                                
                                                
                                                
                                                
                                                
                                                 8008 단어  GoogleCloudSpeechAPItwilioRails
                    
개요
Twilio 및 GoogleCloudSpeechAPI를 사용하여 Rails에서 통화 내용을 음성 인식
 절차
 GoogleCloudSpeechAPI 사용
 htps : // 이런. cぉd. 오, ぇ. 코m/
 
 
 Google 서비스 계정 키 만들기
 
 
파일이 다운로드되므로 저장
 Gem 설치
gem 'twilio-ruby'
gem 'google-cloud-speech'
 Rails 앱 만들기
call_controller.rbrequire 'google/cloud/speech'
class CallController < ApplicationController
  def transcription
    recording_url = params[:RecordingUrl]
    voice = 'man'
    language = 'ja-JP'
    response = Twilio::TwiML::VoiceResponse.new
    if recording_url.blank?
      response.say('お名前をフルネームで教えてください。', voice: voice, language: language)
      response.record(timeout: 5, max_length: 5)
    else
      project = 'プロジェクトID'
      keyfile = 'サービスアカウントキーのファイルのパス'
      speech = Google::Cloud::Speech.new project: project, keyfile: keyfile
      audio = speech.audio open(recording_url),
                   encoding: :linear16,
                   language: 'ja-JP',
                   sample_rate: 8000
      results = audio.recognize
      result = results.first
      if result.present?
        transcript = result.transcript
        response.say('あなたの名前は、', voice: voice, language: language)
        response.say(transcript, voice: voice, language: language)
        response.say('です。', voice: voice, language: language)
      else
        response.say('すみませんが、もう一度お願いします。', voice: voice, language: language)
        response.record(timeout: 5, max_length: 5)
      end
    end
    render :xml => response.to_s
  end
end
 Rails 앱 시작
bundle exec rails s
 ngrok 시작
ngrok http 3000
 
 TwiML 앱 만들기
 htps //w w. 그리고 오. 코m/
 htps : // jp. 그리고 오. 코 m / cs / 아피 / 토 ML
 
 TwiML 앱 검토
 
  
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(Rails로 통화 내용을 음성 인식), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/iharakenji/items/22a459dc8241a4d0aa68
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
GoogleCloudSpeechAPI 사용
htps : // 이런. cぉd. 오, ぇ. 코m/


Google 서비스 계정 키 만들기


파일이 다운로드되므로 저장
Gem 설치
gem 'twilio-ruby'
gem 'google-cloud-speech'
Rails 앱 만들기
call_controller.rb
require 'google/cloud/speech'
class CallController < ApplicationController
  def transcription
    recording_url = params[:RecordingUrl]
    voice = 'man'
    language = 'ja-JP'
    response = Twilio::TwiML::VoiceResponse.new
    if recording_url.blank?
      response.say('お名前をフルネームで教えてください。', voice: voice, language: language)
      response.record(timeout: 5, max_length: 5)
    else
      project = 'プロジェクトID'
      keyfile = 'サービスアカウントキーのファイルのパス'
      speech = Google::Cloud::Speech.new project: project, keyfile: keyfile
      audio = speech.audio open(recording_url),
                   encoding: :linear16,
                   language: 'ja-JP',
                   sample_rate: 8000
      results = audio.recognize
      result = results.first
      if result.present?
        transcript = result.transcript
        response.say('あなたの名前は、', voice: voice, language: language)
        response.say(transcript, voice: voice, language: language)
        response.say('です。', voice: voice, language: language)
      else
        response.say('すみませんが、もう一度お願いします。', voice: voice, language: language)
        response.record(timeout: 5, max_length: 5)
      end
    end
    render :xml => response.to_s
  end
end
Rails 앱 시작
bundle exec rails s
ngrok 시작
ngrok http 3000

TwiML 앱 만들기
htps //w w. 그리고 오. 코m/
htps : // jp. 그리고 오. 코 m / cs / 아피 / 토 ML

TwiML 앱 검토

 
                Reference
이 문제에 관하여(Rails로 통화 내용을 음성 인식), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/iharakenji/items/22a459dc8241a4d0aa68텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)