Paxa Labs

ใช้ Paxa กับ Strands Agents

ให้ agent Strands ใช้เครื่องมือเสียงพูด ถอดเสียง OCR และแปลภาษาของ Paxa ผ่านเซิร์ฟเวอร์ MCP ของ Paxa และ MCP client ที่มีมาใน Strands

ดูเป็น Markdown

ให้ agent Strands Agents ใช้ Paxa API เป็นเครื่องมือ agent จะพูดได้ทั้งภาษาไทย อังกฤษ และจีนกลาง ถอดเสียงไฟล์บันทึกเสียง อ่านเอกสารด้วย OCR และดึงข้อมูลออกมาเป็นฟิลด์ รวมถึงแปลเป็นภาษาไทย

Strands โหลดเครื่องมือจากเซิร์ฟเวอร์ MCP ของ Paxa คือ @paxalabs/mcp ผ่าน MCP client ที่มีมาในตัว จึงไม่ต้องติดตั้งแพ็กเกจเฉพาะสำหรับ Strands

ก่อนเริ่ม#

  • ติดตั้ง Node.js 20 ขึ้นไป หรือ 22 ขึ้นไปหากใช้ listen เพราะเซิร์ฟเวอร์ทำงานผ่าน npx
  • สร้างคีย์ API ที่แดชบอร์ด บัญชีใหม่เริ่มต้นด้วย 100 เครดิตฟรี
  • เลือกผู้ให้บริการโมเดลสำหรับ agent Strands ใช้ Amazon Bedrock เป็นค่าเริ่มต้น และคู่มือผู้ให้บริการโมเดลของ Strands แสดงตัวเลือกอื่น

Python#

Terminal
pip install "strands-agents>=1.62,<2"
export PAXA_API_KEY=pxa_your_key_here
Python
import os

from mcp import StdioServerParameters, stdio_client
from strands import Agent
from strands.tools.mcp import MCPClient

paxa = MCPClient(lambda: stdio_client(
    StdioServerParameters(
        command="npx",
        args=["-y", "@paxalabs/mcp"],
        env={"PAXA_API_KEY": os.environ["PAXA_API_KEY"]},
    )
))

agent = Agent(tools=[paxa])
agent("Save 'สวัสดีครับ, welcome to the show' as welcome.mp3 with the khanomkrok voice.")

agent จะเปิดเซิร์ฟเวอร์เมื่อใช้งานครั้งแรก และปิดเมื่อ agent ทำงานเสร็จ

TypeScript#

Terminal
npm install @strands-agents/sdk @modelcontextprotocol/sdk
export PAXA_API_KEY=pxa_your_key_here
TypeScript
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
import { Agent, McpClient } from "@strands-agents/sdk";

const paxa = new McpClient({
  transport: new StdioClientTransport({
    command: "npx",
    args: ["-y", "@paxalabs/mcp"],
    env: { PAXA_API_KEY: process.env.PAXA_API_KEY ?? "" },
  }),
});

const agent = new Agent({ tools: [paxa] });
await agent.invoke(
  "Save 'สวัสดีครับ, welcome to the show' as welcome.mp3 with the khanomkrok voice.",
);

เลือกเครื่องมือ#

เครื่องมือเล่นเสียง design_voice refine_voice และ listen ใช้ลำโพงและไมโครโฟนของเครื่องที่รันเซิร์ฟเวอร์ agent ที่ทำงานบนเซิร์ฟเวอร์มักต้องการเพียงเครื่องมือที่ทำงานกับไฟล์ ใน Python ให้ส่ง tool_filters ให้ MCPClient เพื่อเลือกเฉพาะเครื่องมือเหล่านั้น

Python
paxa = MCPClient(
    lambda: stdio_client(
        StdioServerParameters(
            command="npx",
            args=["-y", "@paxalabs/mcp"],
            env={"PAXA_API_KEY": os.environ["PAXA_API_KEY"]},
        )
    ),
    tool_filters={
        "allowed": [
            "text_to_speech",
            "transcribe_audio",
            "ocr_document",
            "extract_fields",
            "translate_to_thai",
            "list_voices",
        ]
    },
)

หน้าเซิร์ฟเวอร์ MCP แสดงเครื่องมือทั้งหมดพร้อมราคา ส่วนตัวแปรสภาพแวดล้อม เช่น โฟลเดอร์ปลายทางและเสียงเริ่มต้น ให้ใส่ไว้ใน env คู่กับ PAXA_API_KEY

เสียงพูดทำงานบน Paxa TTS Flash v2 ซึ่งมี 50 เสียง ทุกเสียงพูดได้ทั้งภาษาไทย อังกฤษ และจีนกลาง แท็กคำกำกับที่เขียนลงในข้อความ เช่น [whispering] หรือ [laughs] ใช้กำหนดน้ำเสียง ส่วนการถอดเสียงเป็นพรีวิวงานวิจัย

Strands อธิบาย MCP client ของตัวเองไว้ในคู่มือ MCP tools