代码拉取完成,页面将自动刷新
同步操作将从 sparkle_code_guy/generate_weight_to_ue_character 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
import json
import time
# *******************************************
# *******************************************
from time import sleep
from api_audio import AudioPlay
from send_micro_weight import send_weight
# *******************************************
# *******************************************
import numpy as np
start_time = 0.0
def send_azure_blendshape_weight(animation):
if animation.strip():
animation=json.loads(animation)
frameIndex=animation["FrameIndex"]
weights = np.array(animation["BlendShapes"])
duration_time = frameIndex/60
print("weight_num:",len(weights))
current_time = time.time()
sleep_time = duration_time-(current_time - start_time)
print("duration_time",duration_time,"current spend time:",current_time - start_time)
if sleep_time>0:
print("begin sleep",sleep_time)
sleep(sleep_time)
speed_up = 0
else:
speed_up = sleep_time/(len(weights))
print("more spped",speed_up)
for i,weight in enumerate(weights):
if i % 2 == 0:
continue
send_weight(weight)
time.sleep(1/60+speed_up)
# send_weight([0]*55)
def get_azure_sound_weights(evt):
send_azure_blendshape_weight(evt.animation)
pass
speech_key, service_region = "key", "region"
def oneline_run_message():
from azure.cognitiveservices.speech.audio import AudioOutputConfig
import azure.cognitiveservices.speech as speechsdk
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
speech_config.speech_synthesis_language = "zh-CN"
speech_config.speech_synthesis_voice_name ="zh-CN-XiaoyouNeural"
audio_config = AudioOutputConfig(filename="file2.wav",use_default_speaker=True)
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
speech_synthesizer.viseme_received.connect(get_azure_sound_weights)
ssml = '''<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis"
xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="zh-CN">
<voice name="zh-CN-YunzeNeural">
<mstts:viseme type="FacialExpression"/>
<mstts:express-as style="calm" styledegree="1">
愿你眼眸有星辰。心中有大海。每一岁都奔走在自己的热爱里。所有的一切都渐入佳境,既要今朝醉。也要万年长! 你的新年好运正在派件。请保持好心情。
新的一年。愿一切困难都能避重就轻。每一次困难都有心中共鸣。山野皆有雾灯。飘摇亦可归舟。所遇皆良善。所行化坦途。
</mstts:express-as>
</voice>
</speak>'''
# If VisemeID is the only thing you want, you can also use `speak_text_async()`
global start_time
start_time = time.time()+2
result = speech_synthesizer.speak_ssml_async(ssml).get()
fi = None
def generate_audio_and_blendshapes():
fi = open('blendshape.txt', 'w', encoding='utf8')
def save_azure_sound_weights(evt):
animation = evt.animation
if animation:
print(animation)
fi.write(animation)
fi.write('\n')
fi.flush()
from azure.cognitiveservices.speech.audio import AudioOutputConfig
import azure.cognitiveservices.speech as speechsdk
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
speech_config.speech_synthesis_language = "zh-CN"
speech_config.speech_synthesis_voice_name = "zh-CN-XiaoyouNeural"
audio_config = AudioOutputConfig(filename="file2.wav")
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
speech_synthesizer.viseme_received.connect(save_azure_sound_weights)
ssml = '''<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis"
xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="zh-CN">
<voice name="zh-CN-YunzeNeural">
<mstts:viseme type="FacialExpression"/>
<mstts:express-as style="calm" styledegree="1">
愿你眼眸有星辰。心中有大海。每一岁都奔走在自己的热爱里。所有的一切都渐入佳境,既要今朝醉。也要万年长! 你的新年好运正在派件。请保持好心情。
新的一年。愿一切困难都能避重就轻。每一次困难都有心中共鸣。山野皆有雾灯。飘摇亦可归舟。所遇皆良善。所行化坦途。
</mstts:express-as>
</voice>
</speak>'''
# If VisemeID is the only thing you want, you can also use `speak_text_async()`
global start_time
start_time = time.time() + 2
result = speech_synthesizer.speak_ssml_async(ssml).get()
def outline_run_message():
player = AudioPlay()
player.play_wav_file_thread(filename="file2.wav")
fr = open('blendshape.txt', 'r', encoding='utf8')
global start_time
start_time = time.time()
for each in fr:
send_azure_blendshape_weight(each)
if __name__ == '__main__':
outline_run_message()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。