Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor & optimize property.json #242

Merged
merged 5 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion agents/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,3 @@ xdump_config
.vscode
*.pyc
*.pyc.*
/property.json
2,538 changes: 2,538 additions & 0 deletions agents/property.json

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions playground/src/common/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,45 @@ export const COLOR_LIST: ColorItem[] = [{
default: "#481C3F"
}]

export type VoiceTypeMap = {
[voiceType: string]: string;
};

export type VendorNameMap = {
[vendorName: string]: VoiceTypeMap;
};

export type LanguageMap = {
[language: string]: VendorNameMap;
};

export const voiceNameMap: LanguageMap = {
"zh-CN": {
azure: {
male: "zh-CN-YunxiNeural",
female: "zh-CN-XiaoxiaoNeural",
},
elevenlabs: {
male: "pNInz6obpgDQGcFmaJgB", // Adam
female: "Xb7hH8MSUJpSbSDYk0k2", // Alice
},
polly: {
male: "Zhiyu",
female: "Zhiyu",
},
},
"en-US": {
azure: {
male: "en-US-BrianNeural",
female: "en-US-JaneNeural",
},
elevenlabs: {
male: "pNInz6obpgDQGcFmaJgB", // Adam
female: "Xb7hH8MSUJpSbSDYk0k2", // Alice
},
polly: {
male: "Matthew",
female: "Ruth",
},
},
};
46 changes: 46 additions & 0 deletions playground/src/common/graph.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { voiceNameMap } from "./constant"

export const getGraphWithLanguage = (graphName: string, language: string) => {
if (graphName == "camera.va.openai.azure") {
if (language == "zh-CN") {
return `${graphName}.cn`
}
return `${graphName}.en`
}
return graphName
}

export const getGraphProperties = (graphName: string, language: string, voiceType: string) => {
if (graphName == "camera.va.openai.azure") {
return {
"agora_rtc": {
"agora_asr_language": language,
},
"openai_chatgpt": {
"model": "gpt-4o"
},
"azure_tts": {
"azure_synthesis_voice_name": voiceNameMap[language]["azure"][voiceType]
}
}
} else if (graphName == "va.openai.azure") {
return {
"agora_rtc": {
"agora_asr_language": language,
},
"azure_tts": {
"azure_synthesis_voice_name": voiceNameMap[language]["azure"][voiceType]
}
}
} else if (graphName == "va.qwen.rag") {
return {
"agora_rtc": {
"agora_asr_language": language,
},
"azure_tts": {
"azure_synthesis_voice_name": voiceNameMap[language]["azure"][voiceType]
}
}
}
return {}
}
1 change: 1 addition & 0 deletions playground/src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ export * from "./utils"
export * from "./storage"
export * from "./request"
export * from "./mock"
export * from "./graph"
9 changes: 4 additions & 5 deletions playground/src/common/request.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { AnyObject } from "antd/es/_util/type"
import { REQUEST_URL } from "./constant"
import { genUUID } from "./utils"

interface StartRequestConfig {
channel: string
userId: number,
language: string
voiceType: string
graphName: string
properties: AnyObject
}

interface GenAgoraDataConfig {
Expand Down Expand Up @@ -35,15 +35,14 @@ export const apiGenAgoraData = async (config: GenAgoraDataConfig) => {

export const apiStartService = async (config: StartRequestConfig): Promise<any> => {
const url = `${REQUEST_URL}/start`
const { language, channel, userId, voiceType, graphName } = config
const { channel, userId, graphName, properties } = config
const data = {
request_id: genUUID(),
agora_asr_language: language,
channel_name: channel,
openai_proxy_url: "",
remote_stream_id: userId,
voice_type: voiceType,
graph_name: graphName,
properties,
}
let resp: any = await fetch(url, {
method: "POST",
Expand Down
2 changes: 1 addition & 1 deletion playground/src/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ export const genUUID = () => {

export const isMobile = () => {
return /Mobile|iPhone|iPad|Android|Windows Phone/i.test(navigator.userAgent)
}
}
10 changes: 6 additions & 4 deletions playground/src/platform/mobile/description/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { setAgentConnected } from "@/store/reducers/global"
import {
DESCRIPTION, useAppDispatch, useAppSelector, apiPing, genUUID,
apiStartService, apiStopService, REQUEST_URL
apiStartService, apiStopService, REQUEST_URL,
voiceNameMap,
getGraphWithLanguage,
getGraphProperties
} from "@/common"
import { message } from "antd"
import { useEffect, useState } from "react"
Expand Down Expand Up @@ -48,9 +51,8 @@ const Description = () => {
const res = await apiStartService({
channel,
userId,
language,
voiceType,
graphName,
graphName: getGraphWithLanguage(graphName, language),
properties: getGraphProperties(graphName, language, voiceType)
})
const { code, msg } = res || {}
if (code != 0) {
Expand Down
10 changes: 6 additions & 4 deletions playground/src/platform/pc/description/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { setAgentConnected } from "@/store/reducers/global"
import {
DESCRIPTION, useAppDispatch, useAppSelector, apiPing, genUUID,
apiStartService, apiStopService, REQUEST_URL
apiStartService, apiStopService, REQUEST_URL,
voiceNameMap,
getGraphWithLanguage,
getGraphProperties
} from "@/common"
import { Select, Button, message, Upload } from "antd"
import { useEffect, useState, MouseEventHandler } from "react"
Expand Down Expand Up @@ -48,9 +51,8 @@ const Description = () => {
const res = await apiStartService({
channel,
userId,
language,
voiceType,
graphName
graphName: getGraphWithLanguage(graphName, language),
properties: getGraphProperties(graphName, language, voiceType)
})
const { code, msg } = res || {}
if (code != 0) {
Expand Down
59 changes: 0 additions & 59 deletions server/internal/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package internal

import (
"log/slog"
"os"
)

type Prop struct {
Expand Down Expand Up @@ -34,9 +33,6 @@ const (
PropertyJsonFile = "./agents/property.json"
// Token expire time
tokenExpirationInSeconds = uint32(86400)
// Voice type
voiceTypeMale = "male"
voiceTypeFemale = "female"
)

var (
Expand Down Expand Up @@ -138,17 +134,8 @@ var (
},
}

// The corresponding graph name based on the language
graphNameMap = map[string]string{
languageChinese: "va.openai.azure",
languageEnglish: "va.openai.azure",
}

// Retrieve parameters from the request and map them to the property.json file
startPropMap = map[string][]Prop{
"AgoraAsrLanguage": {
{ExtensionName: extensionNameAgoraRTC, Property: "agora_asr_language"},
},
"ChannelName": {
{ExtensionName: extensionNameAgoraRTC, Property: "channel"},
},
Expand All @@ -158,54 +145,8 @@ var (
"Token": {
{ExtensionName: extensionNameAgoraRTC, Property: "token"},
},
"VoiceType": {
{ExtensionName: extensionNameAzureTTS, Property: "azure_synthesis_voice_name"},
{ExtensionName: extensionNameElevenlabsTTS, Property: "voice_id"},
},
"WorkerHttpServerPort": {
{ExtensionName: extensionNameHttpServer, Property: "listen_port"},
},
}

// Map the voice name to the voice type
voiceNameMap = map[string]map[string]map[string]string{
languageChinese: {
extensionNameAzureTTS: {
voiceTypeMale: "zh-CN-YunxiNeural",
voiceTypeFemale: "zh-CN-XiaoxiaoNeural",
},
extensionNameElevenlabsTTS: {
voiceTypeMale: "pNInz6obpgDQGcFmaJgB", // Adam
voiceTypeFemale: "Xb7hH8MSUJpSbSDYk0k2", // Alice
},
extensionNamePollyTTS: {
voiceTypeMale: "Zhiyu",
voiceTypeFemale: "Zhiyu",
},
},
languageEnglish: {
extensionNameAzureTTS: {
voiceTypeMale: "en-US-BrianNeural",
voiceTypeFemale: "en-US-JaneNeural",
},
extensionNameElevenlabsTTS: {
voiceTypeMale: "pNInz6obpgDQGcFmaJgB", // Adam
voiceTypeFemale: "Xb7hH8MSUJpSbSDYk0k2", // Alice
},
extensionNamePollyTTS: {
voiceTypeMale: "Matthew",
voiceTypeFemale: "Ruth",
},
},
}
)

func SetGraphNameMap() {
if graphNameZH := os.Getenv("GRAPH_NAME_ZH"); graphNameZH != "" {
graphNameMap[languageChinese] = graphNameZH
}

if graphNameEN := os.Getenv("GRAPH_NAME_EN"); graphNameEN != "" {
graphNameMap[languageEnglish] = graphNameEN
}
}
Loading