问题描述
是否可以在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 (将#修改为@)