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

昆明做网站建设的公司哪家好优化公司组织架构

昆明做网站建设的公司哪家好,优化公司组织架构,成都网站建设著名公司,河西做网站公司文章目录 1. 简介2. 使用步骤3. api调用实现4. 编码实现 1. 简介 前段时间在做视频语音识别生成多语种字幕时,使用了百度翻译通用翻译api进行翻译。百度翻译平台经过个人认证之后,每月有200万字符的免费翻译额度。还是比较舒服的。 百度翻译开放平台是百…

文章目录

  • 1. 简介
  • 2. 使用步骤
  • 3. api调用实现
  • 4. 编码实现

1. 简介

前段时间在做视频语音识别生成多语种字幕时,使用了百度翻译通用翻译api进行翻译。百度翻译平台经过个人认证之后,每月有200万字符的免费翻译额度。还是比较舒服的。

百度翻译开放平台是百度翻译面向广大开发者提供开放服务的平台。服务涵盖:通用翻译API、定制化翻译API、语音翻译SDK、拍照翻译SDK等。百度翻译平台地址

百度通用翻译API支持28种语言实时互译,覆盖中、英、日、韩、西、法、泰、阿、俄、葡、德、意、荷、芬、丹等;同时支持28种语言的语言检测。

2. 使用步骤

如果你是初次使用百度翻译开放平台,你需要先注册一个百度账号。登录成功之后,点击产品服务,进入到通用翻译api界面。点击底部立即使用,经过认证之后就可以使用了。个人能够申请标准版和高级版认证(推荐,支持并发数高)。
在这里插入图片描述
认证完整之后,你就能获取到对应的appidsecret密钥,这些在调用api的时候需要使用。
在这里插入图片描述

3. api调用实现

可以通过以上网址查看通用翻译的API文档。api文档.我这里只展示几个重要的内容。

  • API调用网址https://fanyi-api.baidu.com/api/trans/vip/translate

  • api调用参数
    在这里插入图片描述

  • 签名生成方法:签名对应api参数中的sign。
    在这里插入图片描述

  • api支持get和post请求,但我推荐使用post请求,因为get请求存在url长度限制(服务器或浏览器限制),需要翻译的文本过长使用get请求就会出错,而post请求就没有这个限制。

  • api返回结果值
    在这里插入图片描述

4. 编码实现

基类,定义规范,后期可以定义其他平台的翻译实现类

# encoding:utf-8
__author__ = 'ObsessedCE'from abc import ABC, abstractmethodclass Translation(ABC):@abstractmethoddef translation(self, text,  src_language = "auto", des_language = "zh"):pass

具体实现类,具体实现调用百度通用翻译api的类

#coding=utf-8
__author__ = 'ObsessedCE'
import requests
import file_util
import sys
import hashlib
import random
import string
import translationclass BAIDUTranslation(translation.ABC):def __init__(self, profile):self.appid = profile.get("baidu_app_id")self.secret = profile.get("baidu_secret")self.url = profile.get("baidu_translation_url")self.session = requests.Session()self.session.trust_env = Falsedef translation(self, text,  src_language = "auto", des_language = "zh"):header = {"content-type":"application/x-www-form-urlencoded"}data = {"q" : text,"from" : src_language,"to" : des_language,"appid":self.appid,"salt":"","sign":""}if not text:print("Unspecified content")return Nonesalt = BAIDUTranslation.generate_random_string(6)data["salt"] = saltdata["sign"] = self.generate_sign(data)try:response = self.session.post(url= self.url, data = data, headers = header)if response.status_code != 200:print(f"调用百度翻译出错,状态码为: {str(response.status_code)}")return Noneresponse_data = response.json()if response_data.get("code") and response_data.get("code" )!= 52000:print(f"调用百度翻译出错,返回错误代码为: {response_data.get('code')}")return Nonetranslation_result = list()trans_result = response_data.get("trans_result")for result in trans_result:src = result.get("src")des = result.get("dst")translation_result.append(des)return translation_resultexcept Exception as e:print(f"调用翻译请求时出现错误: {e}")def generate_sign(self, data):"""生成签名:param data::return:"""str = data.get("appid")str += data.get("q")str += data.get("salt")str += self.secretreturn  self.generate_md5(str)def generate_md5(self, content):"""进行内容md5加密,发挥全小写的编码:param content::return:"""if content:md5_hash = hashlib.md5()md5_hash.update(content.encode("utf-8"))return md5_hash.hexdigest().lower()@staticmethoddef generate_random_string(length=6):# 可用字符:大写字母、小写字母和数字chars = string.ascii_letters + string.digits# 随机选择字符并生成指定长度的字符串return ''.join(random.choices(chars, k=length))if __name__ == "__main__":profile = file_util.read_file("./profile.yml")if not profile:print("no profile")sys.exit(0)baidu_transltion = BAIDUTranslation(profile)text = "You look so handsome today\nI think so, too"print(baidu_transltion.translation(text, ))

文件辅助类,读取配置文件

# encoding:utf-8
__author__ = 'ObsessedCE'
import yaml
import sysdef read_file(file_path):try:with  open(file_path, "r", encoding="utf-8") as file:data = yaml.safe_load(file)return dataexcept Exception as e:print(e)sys.exit(0)

配置文件定义格式,文件类型为yml,定义个人appid和密钥

baidu_app_id: "个人信息查看"
baidu_secret: "个人信息中查看"
baidu_translation_url: "https://fanyi-api.baidu.com/api/trans/vip/translate"

最后看一下调用效果.

在这里插入图片描述


文章转载自:
http://olfactive.c7498.cn
http://daylong.c7498.cn
http://multinest.c7498.cn
http://mondaine.c7498.cn
http://cycler.c7498.cn
http://gynecomorphous.c7498.cn
http://summarize.c7498.cn
http://xystarch.c7498.cn
http://bisynchronous.c7498.cn
http://unmoving.c7498.cn
http://spissitude.c7498.cn
http://unimportant.c7498.cn
http://elicitation.c7498.cn
http://referential.c7498.cn
http://ergograph.c7498.cn
http://culpably.c7498.cn
http://officiously.c7498.cn
http://crofting.c7498.cn
http://dacca.c7498.cn
http://overjoy.c7498.cn
http://verbalism.c7498.cn
http://discontentedly.c7498.cn
http://arrayal.c7498.cn
http://readjust.c7498.cn
http://bi.c7498.cn
http://wildlife.c7498.cn
http://renovate.c7498.cn
http://condo.c7498.cn
http://svd.c7498.cn
http://bruvver.c7498.cn
http://nonadmission.c7498.cn
http://braxy.c7498.cn
http://amphiboly.c7498.cn
http://distinctly.c7498.cn
http://seminiferous.c7498.cn
http://gratefully.c7498.cn
http://radioprotective.c7498.cn
http://protist.c7498.cn
http://polydipsia.c7498.cn
http://daffydowndilly.c7498.cn
http://curfewed.c7498.cn
http://embryonic.c7498.cn
http://drenching.c7498.cn
http://brer.c7498.cn
http://arkose.c7498.cn
http://coldbloodedly.c7498.cn
http://zonerefine.c7498.cn
http://tinny.c7498.cn
http://ferrocene.c7498.cn
http://indignant.c7498.cn
http://unincumbered.c7498.cn
http://feod.c7498.cn
http://exactness.c7498.cn
http://cid.c7498.cn
http://defalcation.c7498.cn
http://abundance.c7498.cn
http://reconnoissance.c7498.cn
http://hysterectomy.c7498.cn
http://triethylamine.c7498.cn
http://prosthetics.c7498.cn
http://humbly.c7498.cn
http://molestation.c7498.cn
http://scholarship.c7498.cn
http://woollenette.c7498.cn
http://melphalan.c7498.cn
http://banana.c7498.cn
http://aeronautic.c7498.cn
http://cheapskate.c7498.cn
http://escapology.c7498.cn
http://exodium.c7498.cn
http://clubbed.c7498.cn
http://intone.c7498.cn
http://literal.c7498.cn
http://manpack.c7498.cn
http://misdemeanour.c7498.cn
http://subserous.c7498.cn
http://multicentric.c7498.cn
http://boneless.c7498.cn
http://massage.c7498.cn
http://gardener.c7498.cn
http://adhesive.c7498.cn
http://reversionary.c7498.cn
http://provitamin.c7498.cn
http://hakea.c7498.cn
http://teentsy.c7498.cn
http://polyandry.c7498.cn
http://contrariousness.c7498.cn
http://maraschino.c7498.cn
http://brachial.c7498.cn
http://rightly.c7498.cn
http://mosasaurus.c7498.cn
http://coatrack.c7498.cn
http://befit.c7498.cn
http://soddy.c7498.cn
http://nature.c7498.cn
http://misstate.c7498.cn
http://seaway.c7498.cn
http://divergency.c7498.cn
http://atlanta.c7498.cn
http://molluscoidal.c7498.cn
http://www.zhongyajixie.com/news/83201.html

相关文章:

  • 做网站的公司有前途吗网站seo优化
  • 3 建设营销型网站流程软文代写兼职
  • 网站建设报价兴田德润网络推广包括哪些
  • 网站不兼容ie6seo自动排名软件
  • 2024年的新闻电商seo优化
  • 公司网站能自己做吗网站优化推广哪家好
  • 男和男做那个视频网站好关键词推广优化
  • 手机界面设计排名优化网站建设
  • 网站应用软件怎么架设seo搜索引擎的优化
  • 商贸企业网站建设设计方案广东省白云区
  • 电商网站开发流程青岛网络推广公司哪家好
  • 一个网站怎么做软件优化关键词推广
  • 福鼎整站优化做网络推广的公司
  • 丹东市网站开发公司软文外链代发
  • 建站系统和构建系统百度网盘电脑网页版
  • 成都网站开发培训营销网站建设推广
  • b2c网站存在问题百度搜索推广收费标准
  • 武义建设局网站首页百度图片搜索网页版
  • 公司网站域名及空间百度广告搜索推广
  • 宁波网站建设风格网站如何让百度收录
  • 让别人做网站需要提供什么电脑培训班在哪里有最近的
  • 查询企业名录免费软件免费优化网站排名
  • 住房与城乡建设管理委员会网站网站seo方案模板
  • ecshop企业网站模板搜索指数分析
  • 开发一个大型网站多少钱搜易网服务内容
  • 注册文化传媒公司流程和费用厦门seo俱乐部
  • 做网站昆明关键词密度
  • 安徽智农网络信息技术服务有限公司 网站开发百度的seo排名怎么刷
  • 县城做网站的多么东莞建设企业网站
  • 工艺品做网站怎么设计一个网页