如何解决是否可以在持久函数azure中运行azure speech_recognizer?
是否可以在python持久函数中对文本运行Azure语音?我收到错误消息:检测到不确定的工作流程:TaskScheduledEvent:0 TaskScheduled STTfunction
我在计算机上进行了本地测试。
我的DurableFunctionsorchestrator看起来像这样
def orchestrator_function(context: df.DurableorchestrationContext):
# 0. Get inpur
input = context.get_input()
parallel_tasks = []
for i,splited_audio in enumerate(input ["splited_audio_list"]):
data = {"action": "transcribe","audio": splited_audio,"lang": input["lang"]}
parallel_tasks.append(context.call_activity("STTfunction",data))
if(len(split["splited_audio_list"])-1==i):
break
transcribe = yield context.task_all(parallel_tasks)
return transcribe
和这样的STT功能
def main(name):
input_args=name
action=input_args["action"]
if(action=="transcribe"):
converted=input_args
transcribing=STTAzure(converted['audio']['file_path'],converted["lang"],converted["audio"]["start"])
result=transcribing.no_async_call()
return result
class STTAzure:
def __init__(self,filename,lang,start_time_sec=0):
self.speech_key="----"
self.service_region="----"
# Settings
self.speech_config = speechsdk.SpeechConfig(subscription=self.speech_key,region=self.service_region)
self.speech_config.enable_dictation()
# Set profanity. Allowed values are "Masked","Removed",and "Raw".
# speech_config.set_profanity(speechsdk.ProfanityOption.Masked)
self.speech_config.request_word_level_timestamps()
self.speech_config.output_format=speechsdk.OutputFormat.Detailed
self.speech_config.speech_recognition_language=lang
self.audio_config = speechsdk.audio.AudioConfig(filename=filename)
self.speech_recognizer = speechsdk.SpeechRecognizer(speech_config=self.speech_config,audio_config=self.audio_config)
self.start_time_sec=start_time_sec
# 1. Convert start time from sec to sth
self.start_time=self.start_time_sec * 10000
self.parts=[]
self.done=False
def no_async_call(self):
result = self.speech_recognizer.recognize_once()
if result.reason == speechsdk.ResultReason.RecognizedSpeech:
to_return={"status":"success","parts": [self.get_text(result.json)]}
elif result.reason == speechsdk.ResultReason.NoMatch:
to_return={"status":"empty","msg":"No speech Could be recognized: {}".format(result.no_match_details)}
elif result.reason == speechsdk.ResultReason.Canceled:
cancellation_details = result.cancellation_details
to_return={"status":"error","msg":"Speech Recognition canceled: {}".format(cancellation_details.reason)}
if cancellation_details.reason == speechsdk.CancellationReason.Error:
to_return={"status":"error","msg":"Error details: {}".format(cancellation_details.error_details)}
return to_return
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。