I do english application for pronoun correctly.My Problem about save .wav file from user speech.
Code user speech recording.
.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getAction() == MotionEvent.ACTION_DOWN){
Toast.makeText(getApplicationContext(), "Recording...", Toast.LENGTH_LONG).show();
MediaRecorderReady();
try {
mediaRecorder.prepare();
mediaRecorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}else if(motionEvent.getAction() == MotionEvent.ACTION_UP){
Toast.makeText(getApplicationContext(), "Audio Recorder successfully", Toast.LENGTH_SHORT).show();
if (mediaRecorder != null){
try{
mediaRecorder.stop();
}catch (RuntimeException e){
}finally {
mediaRecorder.release();
mediaRecorder = null;
uploadSound1(view);
Toast.makeText(StudyingActivity.this,"Successes upload 2",Toast.LENGTH_LONG).show();
}
}
}
return false;
}
});
private void MediaRecorderReady() {
SimpleDateFormat formatter = new SimpleDateFormat("dd_MM_yyyy", Locale.KOREA);
Date now = new Date();
String outputFile = Environment.getExternalStorageDirectory().getAbsolutePath()+"/"+"record_"+formatter.format(now)+".wav";
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
mediaRecorder.setOutputFile(outputFile);
}
Sound.py file
import librosa
import librosa.display
import matplotlib.pyplot as plt
from numpy.linalg import norm
from dtw import dtw
import datetime
today_date = datetime.date.today()
new_today_date = today_date.strftime('%d_%m_%Y')
name = 'record_'+(new_today_date)+'.wav'
y1, sr1 = librosa.load('words-english.wav')
y2, sr2 = librosa.load(name)
plt.subplot(1, 2, 1)
mfcc1 = librosa.feature.mfcc(y1,sr1)
librosa.display.specshow(mfcc1)
plt.subplot(1, 2, 2)
mfcc2 = librosa.feature.mfcc(y2, sr2)
librosa.display.specshow(mfcc2)
dist, cost, acc_cost, path = dtw(mfcc1.T, mfcc2.T, dist=lambda x, y: norm(x - y, ord=1))
print('%.3f' % dist)
librosa.output.write_wav('1.wav', y1, sr1)
What I have tried:
I can't read audiorecord from user speech (.wav) to python file but I can read TTS(Text to speech sound).
This Error in sound.py
D:\Users\Python\Python36\lib\site-packages\librosa\core\audio.py:14
warnings.warn('PySoundFile failed. Trying audioread instead.')
Traceback (most recent call last):
File "D:\Users\Python\Python36\lib\site-packages\librosa\core\aud
RuntimeError: Error opening 'record_15_12_2019.wav': File contains data in an unknown format.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "d:/xampp/htdocs/wordsapp/sound/sound.py", line 17, in <module>
y2, sr2 = librosa.load('record.wav')
File "D:\Users\Python\Python36\lib\site-packages\librosa\core\audio.py", line 147, in load
y, sr_native = __audioread_load(path, offset, duration, dtype)
File "D:\Users\Python\Python36\lib\site-packages\librosa\core\audio.py", line 171, in __audioread_load
with audioread.audio_open(path) as input_file:
File "D:\Users\Python\Python36\lib\site-packages\audioread\__init__.py", line 116, in audio_open
raise NoBackendError()
audioread.exceptions.NoBackendError