การป้อนข้อมูลด้วยเสียง
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
อุปกรณ์ Wear OS ทุกเครื่องมาพร้อมกับไมโครโฟน ผู้ใช้จึงใช้เสียงเพื่อโต้ตอบกับ
อุปกรณ์ คุณสามารถแบ่งการโต้ตอบเหล่านี้ได้ 3 ประเภท ดังนี้
- บันทึกเสียง
- รับการป้อนข้อมูลด้วยเสียงพูดในรูปแบบอิสระ
- การสั่งงานด้วยเสียง
บันทึกเสียง
การบันทึกเสียงในอุปกรณ์ Wear OS จะทำงานในลักษณะเดียวกันกับการบันทึกบนโทรศัพท์ โปรดดู
เอกสาร MediaRecorder เพื่อเรียนรู้เกี่ยวกับ
บันทึกเสียงใน Android นอกจากนี้ คุณยังดูตัวอย่างการใช้งานได้ใน
ตัวอย่างลำโพง Wear
ใน GitHub
เรียกใช้กิจกรรมการจดจำคำพูดในตัวของระบบเพื่อรับการป้อนข้อมูลด้วยเสียงพูดจากผู้ใช้ ใช้เสียงพูด
เพื่อส่งข้อความหรือทำการค้นหา
ในแอป ให้โทรหา startActivityForResult()
โดยใช้ ACTION_RECOGNIZE_SPEECH
การดำเนินการ การดำเนินการดังกล่าวจะเริ่มต้นกิจกรรมการจดจำเสียง จากนั้นคุณสามารถจัดการผลลัพธ์ใน
onActivityResult()
ตัวอย่างโค้ดต่อไปนี้แสดงวิธีเริ่มและจัดการกิจกรรมการจดจำคำพูด
var textForVoiceInput by remember { mutableStateOf("") }
val voiceLauncher =
rememberLauncherForActivityResult(
ActivityResultContracts.StartActivityForResult()
) { activityResult ->
// This is where you process the intent and extract the speech text from the intent.
activityResult.data?.let { data ->
val results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)
textForVoiceInput = results?.get(0) ?: "None"
}
}
val scrollState = rememberScrollState()
ScreenScaffold(scrollState = scrollState) {
// rest of implementation here
// ...
Column(
// rest of implementation here
// ...
// Create an intent that can start the Speech Recognizer activity
val voiceIntent: Intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {
putExtra(
RecognizerIntent.EXTRA_LANGUAGE_MODEL,
RecognizerIntent.LANGUAGE_MODEL_FREE_FORM
)
putExtra(
RecognizerIntent.EXTRA_PROMPT,
stringResource(R.string.voice_text_entry_label)
)
}
// Invoke the process from a chip
Chip(
onClick = {
voiceLauncher.launch(voiceIntent)
},
label = stringResource(R.string.voice_input_label),
secondaryLabel = textForVoiceInput
)
}
}
การทำงานด้วยเสียง
ขณะนี้ระบบยังไม่รองรับการสั่งงานด้วยเสียงและการดำเนินการของแอป Assistant ยกเว้นแอป Wear OS ใน
จีน อ่านเพิ่มเติมเกี่ยวกับ
การสนับสนุนการสั่งงานด้วยเสียง
สำหรับประเทศจีน
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-09-04 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-09-04 UTC"],[],[],null,["Every Wear OS device comes with a microphone, so users can use their voice to interact with the\ndevice. You can divide these into three types of interactions:\n\n- Record audio\n- Get free-form speech input\n- Voice actions\n\nRecord audio\n\n\nRecording audio on a Wear OS device works the same way as it would on a phone. Refer to the\n[MediaRecorder documentation](/guide/topics/media/mediarecorder) to learn more about\nrecording audio on Android. You can also look at a sample implementation in the\n[Wear Speaker sample](https://github.com/android/wear-os-samples/tree/main/WearSpeakerSample)\non Github.\n\nGet free-form speech input\n\n\nCall the system's built-in Speech Recognizer activity to get speech input from users. Use speech\ninput to send messages or perform searches.\n\n\nIn your app, call [startActivityForResult()](/reference/android/app/Activity#startActivityForResult(android.content.Intent, int))\nusing the [ACTION_RECOGNIZE_SPEECH](/reference/android/speech/RecognizerIntent#ACTION_RECOGNIZE_SPEECH)\naction. This starts the speech recognition activity, and you can then handle the result in\n[onActivityResult()](/reference/android/app/Activity#onActivityResult(int, int, android.content.Intent)).\n\n\nThe following code sample shows how to start and handle a speech recognition activity. \n\n```kotlin\nvar textForVoiceInput by remember { mutableStateOf(\"\") }\n\nval voiceLauncher =\n rememberLauncherForActivityResult(\n ActivityResultContracts.StartActivityForResult()\n ) { activityResult -\u003e\n // This is where you process the intent and extract the speech text from the intent.\n activityResult.data?.let { data -\u003e\n val results = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS)\n textForVoiceInput = results?.get(0) ?: \"None\"\n }\n }\n\nval scrollState = rememberScrollState()\n\nScreenScaffold(scrollState = scrollState) {\n // rest of implementation here\n // ...\n Column(\n // rest of implementation here\n // ...\n\n // Create an intent that can start the Speech Recognizer activity\n val voiceIntent: Intent = Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH).apply {\n putExtra(\n RecognizerIntent.EXTRA_LANGUAGE_MODEL,\n RecognizerIntent.LANGUAGE_MODEL_FREE_FORM\n )\n\n putExtra(\n RecognizerIntent.EXTRA_PROMPT,\n stringResource(R.string.voice_text_entry_label)\n )\n }\n // Invoke the process from a chip\n Chip(\n onClick = {\n voiceLauncher.launch(voiceIntent)\n },\n label = stringResource(R.string.voice_input_label),\n secondaryLabel = textForVoiceInput\n )\n }\n}https://github.com/android/snippets/blob/3d5181b4813a17a1c236b134cc207dfee625885c/wear/src/main/java/com/example/wear/snippets/voiceinput/VoiceInputScreen.kt#L73-L133\n```\n\nVoice Actions\n\nVoice Actions and Assistant App Actions aren't supported at this time except for Wear OS apps in\nChina. Read more about\n[Voice Actions support\nfor China](/training/wearables/apps/creating-app-china#voice-actions-support)."]]