You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何将Web Speech API转写的口语化邮箱地址转换为标准格式

解决方案

可以通过正则表达式实现格式转换,适配你给出的两种常见语音转写邮箱的错误格式,还可扩展适配更多口语化转写变体。基于Chrome浏览器调用Web Speech API的前端场景,直接用JavaScript实现即可:

核心逻辑

语音转写的邮箱错误主要匹配两类模式:

  • 用户名 + at the rate + 域名
  • 用户名 + at + 域名
    通过正则捕获分组提取用户名和域名,替换为用户名@域名格式,最后通过集合去重即可得到标准化的唯一邮箱列表。

实现代码

// 传入语音转写的原始文本,返回标准化去重后的邮箱数组
function normalizeTranscriptEmails(rawTranscript) {
  const lineList = rawTranscript.split('\n').map(item => item.trim()).filter(Boolean);
  const uniqueEmailSet = new Set();
  // 匹配两类口语化at表述,忽略大小写
  const emailMatchReg = /(.*?)\s+(?:at the rate|at)\s+([a-z0-9.-]+\.[a-z]{2,})/i;

  lineList.forEach(line => {
    const matchResult = line.match(emailMatchReg);
    if (matchResult) {
      const userName = matchResult[1].trim().toLowerCase();
      const domain = matchResult[2].trim().toLowerCase();
      uniqueEmailSet.add(`${userName}@${domain}`);
    }
  })
  return Array.from(uniqueEmailSet);
}

// 测试效果
const testRawText = `David at the rate gmail.com
David at Gmail.com
Stacy at the rate gmail.com
Stacy at Gmail.com`;

console.log(normalizeTranscriptEmails(testRawText));
// 输出结果:["david@gmail.com", "stacy@gmail.com"]

扩展适配

如果后续出现更多口语化转写错误,比如将.识别为dot/点,可在域名处理环节增加一层替换逻辑即可:

// 示例:处理域名中的dot表述
const domain = matchResult[2].trim().toLowerCase().replace(/\s+(dot|点)\s+/ig, '.');

内容的提问来源于stack exchange,提问作者Siddharth

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.28 07:54:05