귀하의 질문에 저장 나에게
public void startRecording(View view) throws IOException {
startButton.setEnabled(false);
stopButton.setEnabled(true);
File sampleDir = Environment.getExternalStorageDirectory();
try {
audiofile = File.createTempFile("sound", ".3gp", sampleDir);
} catch (IOException e) {
Log.e(TAG, "sdcard access error");
return;
}
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audiofile.getAbsolutePath());
recorder.prepare();
recorder.start();
}
을 filenames.help 방법 모두를 저장하는 루프를 만드는 사용자로부터 파일 이름을 얻어서 이것에 대한 루프를 만들고 싶어 이해하기 어렵다.
사용자가 제공하는 새 이름으로 TempFile "sound.3gp"를 저장하는 방법을 알고 싶습니까? 이 경우 : 파일 이름을 입력하도록 사용자를 얻을 다음 해당 파일에 직접 오디오를 녹음하려면
try {
InputStream dataIn = new FileInputStream(tempFile);
OutputStream dataOut = new FileOutputStream(userFile);
// copy the data from the temp file to the new user file
byte[] myBuffer = new byte[1024];
int bytesRead;
while ((bytesRead= dataIn.read(myBuffer)) > 0) {
dataOut.write(myBuffer, 0, bytesRead);
}
} finally {
dataIn.close();
dataOut.close();
}
<Additional>
은 당신이 할 수있는 다음
// Get the file name from the user
String usersFileName = usersFileNameEditText.getText().toString() + ".3gp";
// Replace any blank spaces they may have put in their file name
usersFileName.replace(" ", "\\");
// Create the file
File sampleDir = Environment.getExternalStorageDirectory();
try {
File usersFile = new File(sampleDir, audiofile);
} catch (IOException e) {
Log.e(TAG, "sdcard access error");
return;
}
// Record the audio
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audiofile.getAbsolutePath());
recorder.prepare();
recorder.start();
...
사용자가 자신의 파일 이름을 지정할 수 있으므로 동일한 이름의 파일이 이미 현재 디렉토리에 저장되어 있는지 확인해야 할 수 있으므로 코드를 조정하십시오.
...
if (audiofile.exists()) {
// A file with this name already exists.
// Ask the user if they want to continue and overwrite the existing file.
// or enter a different file name.
} else {
// File does not already exist so go ahead and start the recording
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audiofile.getAbsolutePath());
recorder.prepare();
recorder.start();
...
}
...
어려운 문제 : 문제 : 위의 코드를 사용하여 하나의 오디오 파일을 저장할 수 있지만 다시 내 코드에 문제가 생기면 이름에 정적 값을 부여하기 때문에 어떻게 모든 음성 녹음 오디오 파일을 저장하는 조건을 만들기 위해, 이것은 내 최대 영어입니다 ;-) –
그게 명확하게. 고맙습니다. 내 대답을 업데이트 할게. –
프로그래밍에 관해 이야기 할 수있을만큼 외국어를 말할 수 없으므로 저보다 더 잘하고 있습니다! :-) –