คู่มือนี้อธิบายวิธีการรวมคลาส Whisper และ Recorder ในแอพ Android สำหรับการบันทึกเสียงและการรู้จำเสียงพูด
นี่คือตัวอย่างรหัสแยกต่างหากสำหรับการใช้ Whisper และ Recorder :
การเริ่มต้นและการกำหนดค่า:
// Initialize Whisper
Whisper mWhisper = new Whisper ( this ); // Create Whisper instance
// Load model and vocabulary for Whisper
String modelPath = getFilePath ( "whisper-tiny.tflite" ); // Provide model file path
String vocabPath = getFilePath ( "filters_vocab_multilingual.bin" ); // Provide vocabulary file path
mWhisper . loadModel ( modelPath , vocabPath , true ); // Load model and set multilingual mode
// Set a listener for Whisper to handle updates and results
mWhisper . setListener ( new IWhisperListener () {
@ Override
public void onUpdateReceived ( String message ) {
// Handle Whisper status updates
}
@ Override
public void onResultReceived ( String result ) {
// Handle transcribed results
}
});การถอดความ:
// Set the audio file path for transcription. Audio format should be in 16K, mono, 16bits
String waveFilePath = getFilePath ( "your_audio_file.wav" ); // Provide audio file path
mWhisper . setFilePath ( waveFilePath ); // Set audio file path
// Start transcription
mWhisper . setAction ( Whisper . ACTION_TRANSCRIBE ); // Set action to transcription
mWhisper . start (); // Start transcription
// Perform other operations
// Add your additional code here
// Stop transcription
mWhisper . stop (); // Stop transcriptionการเริ่มต้นและการกำหนดค่า:
// Initialize Recorder
Recorder mRecorder = new Recorder ( this ); // Create Recorder instance
// Set a listener for Recorder to handle updates and audio data
mRecorder . setListener ( new IRecorderListener () {
@ Override
public void onUpdateReceived ( String message ) {
// Handle Recorder status updates
}
@ Override
public void onDataReceived ( float [] samples ) {
// Handle audio data received during recording
// You can forward this data to Whisper for live recognition using writeBuffer()
// mWhisper.writeBuffer(samples);
}
});การบันทึก:
// Check and request recording permissions
checkRecordPermission (); // Check and request recording permissions
// Set the audio file path for recording. It record audio in 16K, mono, 16bits format
String waveFilePath = getFilePath ( "your_audio_file.wav" ); // Provide audio file path
mRecorder . setFilePath ( waveFilePath ); // Set audio file path
// Start recording
mRecorder . start (); // Start recording
// Perform other operations
// Add your additional code here
// Stop recording
mRecorder . stop (); // Stop recordingโปรดปรับตัวอย่างโค้ดเหล่านี้ให้เข้ากับกรณีการใช้งานเฉพาะของคุณระบุเส้นทางไฟล์ที่ถูกต้องและจัดการข้อยกเว้นอย่างเหมาะสมในแอปพลิเคชันของคุณ
หมายเหตุ : ตรวจสอบให้แน่ใจว่าคุณมีสิทธิ์ที่จำเป็นการจัดการข้อผิดพลาดและการจัดการเส้นทางไฟล์ในแอปพลิเคชันของคุณเมื่อใช้คลาส Recorder
Whisper ASR เป็นเครื่องมือที่ทรงพลังสำหรับการถอดคำพูดลงในข้อความ อย่างไรก็ตามโปรดทราบว่าการจัดการข้อมูลเสียงและการถอดความอาจต้องมีการซิงโครไนซ์อย่างระมัดระวังและการจัดการข้อผิดพลาดในแอปพลิเคชัน Android ของคุณเพื่อให้แน่ใจว่าประสบการณ์ผู้ใช้ที่ราบรื่น
เพลิดเพลินไปกับการใช้แอพ Android Whisper ASR เพื่อเพิ่มขีดความสามารถในการจดจำคำพูดของคุณ!