当前位置: 首页 > news >正文

什么语言做网站好没干过网络推广能干吗

什么语言做网站好,没干过网络推广能干吗,杭州高端网站建设,有没有如何做网站的书文章目录 一、FunASR二、上代码#xff08;队列解决线程并发问题#xff09;三、测试 一、FunASR 在我的另一个博客有介绍FunASR,并且进行了语者分离#xff0c;不过最近FunASR自带了语者分离#xff0c;挺好挺好#xff0c;但是一直看社区就是大家都用python写#xff… 文章目录 一、FunASR二、上代码队列解决线程并发问题三、测试 一、FunASR 在我的另一个博客有介绍FunASR,并且进行了语者分离不过最近FunASR自带了语者分离挺好挺好但是一直看社区就是大家都用python写会出现线程不安全问题群里有大佬说使用多态服务器感觉很浪费 二、上代码队列解决线程并发问题 import osimport uuidimport copyimport jsonimport loggingimport queueimport threadingimport numpy as npimport torchfrom flask import Flaskfrom flask import request, jsonifyfrom modelscope.pipelines import pipelinefrom modelscope.utils.constant import Tasksapp Flask(__name__)# 创建一个队列pipeline_queue queue.Queue()# 实例对象的计数器来存储实例的数量created_instances 0# logging.basicConfig(filenameapp.log, levellogging.INFO)# logger logging.getLogger(info)# # 再创建一个handler用于输出到控制台# ch logging.StreamHandler()# ch.setLevel(logging.INFO)# # 定义handler的输出格式# formatter logging.Formatter(%(asctime)s - %(name)s - %(levelname)s - %(message)s)# ch.setFormatter(formatter)# # 给logger添加handler# logger.addHandler(ch)def flask_content_type(req) - dict:根据不同的content_type来解析数据if req.method POST or req.method PUT:if application/x-www-form-urlencoded req.content_type or form-data in req.content_type:data req.formelse: # 无法被解析出来的数据if req.data:data json.loads(req.data)else:raise Exception(无法解析)elif req.method GET:data req.argselse:raise Exception(不支持的请求方式)return copy.copy(data)def create_pipelines(num_pipelines):Descriptionnum_pipelines:创建pipeline实例的数量根据你的显存大小创建一个实例需要占用2GBfor _ in range(num_pipelines):global created_instancesinference_pipeline pipeline(taskTasks.auto_speech_recognition,model/root/autodl-tmp/models_from_modelscope/damo/speech_paraformer-large-vad-punc-spk_asr_nat-zh-cn,model_revisionv0.0.2,vad_model/root/autodl-tmp/models_from_modelscope/damo/speech_fsmn_vad_zh-cn-16k-common-pytorch,punc_model/root/autodl-tmp/models_from_modelscope/damo/punc_ct-transformer_cn-en-common-vocab471067-large)pipeline_queue.put(inference_pipeline)print(成功创建实例)# 更新已创建实例的数量created_instances 1print(f队列现有空闲实例数量为{pipeline_queue.qsize()})print(f实例总数量数量为{created_instances})print()def create_pipelines_thread(num_pipelines):# 创建线程thread threading.Thread(targetcreate_pipelines, args(num_pipelines,))# 启动线程thread.start()return threaddef default_dump(obj):Convert numpy classes to JSON serializable objects.if isinstance(obj, (np.integer, np.floating, np.bool_)):return obj.item()elif isinstance(obj, np.ndarray):return obj.tolist()else:return objapp.route(/queue_size, methods[GET])def get_queue_size():# 获取队列数量queue_size pipeline_queue.qsize()# 构建响应response {queue_size: queue_size}# 返回响应return jsonify(response), 200app.route(/created_instances, methods[GET])def get_created_instances():# 获取已创建的实例数量response {created_instances: created_instances}# 返回响应return jsonify(response), 200app.route(/add_pipeline/int:num, methods[GET])def add_pipeline_queue(num):global created_instancesif (created_instances 10):return jsonify({error: f现有实例数量为{created_instances},无法再添加})print(开始创建实例)print(f队列现有空闲实例数量为{pipeline_queue.qsize()})thread create_pipelines_thread(num)# 等待线程结束thread.join()print(实例创建结束)print(pipeline_queue.qsize())return jsonify({success: f队列现有空闲实例数量为{pipeline_queue.qsize()}现有实例数量为{created_instances}})app.route(/, methods[POST])def result_test():dates flask_content_type(request).copy()print(dates)return jsonify({success: dates})app.route(/transcribe, methods[POST])def transcribe():print(队列剩余)print(pipeline_queue.qsize())# 第一步获取请求体if audio_file in request.files:audio_file request.files[audio_file]file_ext os.path.splitext(audio_file.filename)[1]if file_ext.lower() not in [.wav, .mp3]:return jsonify({error: str(Error: Audio file must be either .wav or .mp3)}), 500else:try:# 将音频文件保存到临时文件夹中temp_dir_path tempif not os.path.exists(temp_dir_path):os.makedirs(temp_dir_path)# 保存上传的临时文件file_extension os.path.splitext(audio_file.filename)[1]unique_filename str(uuid.uuid4()) file_extensiontemp_file_path os.path.join(temp_dir_path, unique_filename)audio_file.save(temp_file_path)return start_asr(temp_file_path)except Exception as e:return jsonify({error: str(e)}), 500finally:# 删除临时文件os.remove(temp_file_path)else:dates flask_content_type(request).copy()return start_asr(dates[file_url])def start_asr(temp_file_path):import time# 记录开始时间start_time time.time()inference_pipeline pipeline_queue.get()# 使用 inference pipeline 进行语音转写asr_result inference_pipeline(audio_intemp_file_path, batch_size_token5000,batch_size_token_threshold_s40,max_single_segment_time6000)try:transform time.time() - start_timeasr_result[transform_time] transform# 将语音识别结果转换为json格式result json.dumps(asr_result, ensure_asciiFalse, defaultdefault_dump)return resultexcept Exception as e:print(str(e))# 返回错误信息return jsonify({error: str(e)}), 500finally:pipeline_queue.put(inference_pipeline)def start_flask_app(port):启动 Flask 应用程序并运行在指定端口上在调用 Flask 的 app.run 方法后应用会进入监听状态等待客户端发起请求。这意味着应用会一直停留在 app.run() 这一行不会继续执行后续的 Python 代码。启动 Flask 应用程序前使用多线程的方式创建我这里是32G显存所以默认创建10个实例print()print(开始异步创建实例)print()try:# 清除显卡torch.cuda.empty_cache()except Exception as e:# 返回错误信息print(e)create_pipelines_thread(5)app.run(portport)if __name__ __main__:start_flask_app(9501) 三、测试 二已经给你完整的示例了所以我就不测了我都上生产了你们自己用postman或者代码试一下把有问题再联系我18956043585微信同号 兄弟们这是我的解决方案欢迎交流
http://www.yutouwan.com/news/184682/

相关文章:

  • 如何跟进psd做网站wordpress的登录页面模板
  • 厦门专业网站免费的网页模板网站
  • 丽水微信网站建设公司营销型单页面网站
  • 织梦网站装修公司源码建一个网站流程
  • 门户网站的建设制作单页网站多少钱
  • php网站进后台从零开始学wordpress
  • 网站进入考核期要多久wordpress密码错误
  • 文化建设 设计公司网站公众号怎么开通商城
  • WordPress瀑布流图片站单位网址怎么编
  • 企业系统建设赣州做网站优化
  • 创建app与网站的区别wordpress linux伪静态
  • 个人域名备案快的网站北京的网站建设
  • asp网站开发的背景与环境北京网页设计公司兴田德润优选
  • 网站界面设计如何实现功能美与形式美的统一教你用wordpress
  • 移动网站和定制网站重庆小程序商城开发
  • 网站优化之站外优化技巧潮流设计网站
  • 哪个网站做简历做钓鱼网站用哪种编程语言
  • 网站的建设与运营专业网络工程建设
  • 空间信息网站淘宝网请人做淘宝客网站
  • 网站建设 步骤汕头拿家做网站
  • 专业北京网站建设公司影楼和工作室的区别
  • 可信网站认证 技术支持单位上海搜索优化推广
  • 开发建设网站多久wordpress修改根目录
  • 租网站服务器一个月多少钱北京市建设厅门户网站
  • 成都优秀网站建设做网站要具备哪些
  • 网站开发公司盈利自己做的网站找不到了
  • 开封建站公司注册一个公司的所有流程
  • 网站建设时应该做的优化长沙推广优化公司
  • 电子商务网站建设服务免费公司取名在线
  • 免费查公司青岛官网seo价格