试图将谷歌语音运行到 celery 中的文本,但工作线程正在崩溃。下面是从 celery 任务中执行的代码。
# 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)
在 celery 终端中获取以下堆栈跟踪-
[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)
我们不能从 celery 或任何其他工作线程调用 Google Speech API 吗?如果我错过了什么,请告诉我。已经提到了这个https://github.com/googleapis/python-speech