Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use python3 #7

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pysoundfile
pyaudio
34 changes: 15 additions & 19 deletions script_recording.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#! /usr/bin/env python
# encoding: utf-8

from __future__ import unicode_literals
#! /usr/bin/env python3

import argparse
from codecs import open
Expand Down Expand Up @@ -30,20 +27,20 @@ def record_one(directory, i):

audio = pyaudio.PyAudio()

raw_input(
input(
"""\n\nPress enter to record one sample, say your hotword when "recording..." shows up""")
time.sleep(0.5)

stream = audio.open(format=FORMAT, channels=CHANNELS,
rate=RATE, input=True,
frames_per_buffer=CHUNK)
print "recording..."
print("recording...")
frames = []

for j in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
print "finished recording\n"
print("finished recording\n")

stream.stop_stream()
stream.close()
Expand All @@ -59,15 +56,14 @@ def record_one(directory, i):

def check_audios(durations):
if any([d > MAX_RECORD_DURATION for d in durations]):
print "WARNING: at least one your record seems to have a too long " \
"duration, you are going to have"
print("WARNING: at least one your record seems to have a too long " \
"duration, you are going to have")


def record_and_trim(hotword_key, nb_records=3):
raw_input("Your will have to record your personal hotword." \
" Please be sure to be in a quiet environment." \
" Press enter once you are ready.\n".format(
nb_records))
input("You will have to record your personal hotword." \
" Please be sure to be in a quiet environment." \
" Press enter once you are ready.\n")

directory = os.path.join(FOLDER_BASE, "personal_{0}".format(str(datetime.datetime.now().strftime(DATE_FORMAT))))
os.makedirs(directory)
Expand All @@ -81,9 +77,9 @@ def record_and_trim(hotword_key, nb_records=3):
audio = Audio.from_file(dest_path)
audio.trim_silences(SNR_TRIM)
while audio.duration() > MAX_RECORD_DURATION:
print "WARNING: there seems to be too much noise in your" \
print("WARNING: there seems to be too much noise in your" \
" environment please retry to record this sample by " \
"following the instructions."
"following the instructions.")
record_one(directory, i)
audio = Audio.from_file(dest_path)
audio.trim_silences(SNR_TRIM)
Expand All @@ -93,9 +89,9 @@ def record_and_trim(hotword_key, nb_records=3):
audio_1.duration() - audio_2.duration()) > MAX_DIFFERENCE_DURATION
for i, audio_1 in enumerate(audios) for j, audio_2 in
enumerate(audios) if i < j]):
print "WARNING: there seems to be too much difference between " \
print("WARNING: there seems to be too much difference between " \
"your records please retry to record all of them by following " \
"the instructions."
"the instructions.")
else:
is_validated = True

Expand Down Expand Up @@ -131,8 +127,8 @@ def record_and_trim(hotword_key, nb_records=3):
with open(os.path.join(directory, "config.json"), "wb") as f:
json.dump(config, f, indent=4)

print "Your model has been saved in {0}".format(
os.path.join(os.path.dirname(os.path.realpath(__file__)), directory))
print("Your model has been saved in {0}".format(
os.path.join(os.path.dirname(os.path.realpath(__file__)), directory)))


if __name__ == "__main__":
Expand Down
5 changes: 1 addition & 4 deletions utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
#! /usr/bin/env python
# encoding: utf-8

from __future__ import unicode_literals
#! /usr/bin/env python3

import numpy as np
import soundfile as sf
Expand Down