Callin Google Speech to Text API от Flask Сельдерей разбивает сельдерей - PullRequest
0 голосов
/ 03 мая 2020

Попытка запустить Google речь на текст из сельдерея, но рабочий поток не работает. Ниже приведен код, который выполняется из задачи сельдерея.

# Google speech to text function
from google.cloud import speech_v1p1beta1
from google.cloud.speech_v1p1beta1 import enums 
import io
import os
from google.cloud import speech_v1p1beta1 as speech   
from google.cloud.speech_v1p1beta1 import types  
import wave
from google.cloud import storage
import json
import uuid

def transcribe(filePath, language):
    print("Google Transcribe intiated for " +
          filePath + " in language "+language)
    head, tail = os.path.split(filePath)
    uid = uuid.uuid4().hex
    serverFilePath = 'files/'+uid+"/"+tail
    upload_blob(bucket_name, filePath, serverFilePath)
    storage_uri = "gs://transcribe-bkt/"+serverFilePath

    client = speech_v1p1beta1.SpeechClient()

    # The language of the supplied audio
    language_code = "en-US"

    # Sample rate in Hertz of the audio data sent
    sample_rate_hertz = 44100

    # Encoding of audio data sent. This sample sets this explicitly.
    # This field is optional for FLAC and WAV audio formats.
    encoding = enums.RecognitionConfig.AudioEncoding.MP3
    config = {
        "language_code": language_code,
        "sample_rate_hertz": sample_rate_hertz,
        "encoding": encoding,
        "enable_word_confidence": True,
        "enable_word_time_offsets": True,
        "enable_automatic_punctuation": True
    }
    audio = {"uri": storage_uri}
    try:
        response = client.recognize(config, audio)
        print("Transcribe completed")
        # print(response)
        # write_transcripts(response.results, 'response.json')
        result = response.results[0]
        transcript = result.alternatives[0].transcript  

        return transcript
    except Exception as e:
        print("Error IN Transcribing:", e)

После этой строки он не работает -

response = client.recognize(config, audio)

Получение следующей трассировки стека в терминале сельдерея -

[2020-05-03 21:46:04,761: ERROR/MainProcess] Process 'Worker-1' pid:46661 exited with 'signal 9 (SIGKILL)'
[2020-05-03 21:46:15,212: ERROR/MainProcess] Task app.speech_to_text_task[6f33d360-22c5-474b-98e0-f1c7ca2ab5fc] raised unexpected: WorkerLostError('Worker exited prematurely: signal 9 (SIGKILL).',)
Traceback (most recent call last):
  File "/Users/skytreasure/.virtualenvs/awstranscribe/lib/python2.7/site-packages/billiard/pool.py", line 1175, in mark_as_worker_lost
    human_status(exitcode)),
WorkerLostError: Worker exited prematurely: signal 9 (SIGKILL)

Разве мы не можем вызвать Google Speech API из сельдерея или любой другой рабочий поток? Пожалуйста, дайте мне знать, если я что-то пропустил. Ссылались на это https://github.com/googleapis/python-speech

...