Beispiel #1
0
def plot_toniness():
    with open('assets/phonetics/model.json') as f:
        model = json.loads(f.read())
    plot = dpc.Plot()
    i = 0
    for phonetic, info in model.items():
        for j, frame in enumerate(info['frames']):
            plot.text(f'{phonetic}{j}', i, frame['toniness'])
            i += 1
    plot.show()
os.environ['PHONETIC_ENCODER_RECORDING_PATH'] = args.recording_path
import phonetic_encoder as pe
dlal.comm_set(None)

run_size = pe.audio.run_size()
duration = pe.filea.duration()
samples = 0
features = []

while samples < duration:
    pe.audio.run()
    sample = pe.sample_system()
    params = pe.parameterize(*sample)
    features.append(dlal.speech.get_features(params))
    samples += run_size
    print(f'{samples} / {duration}', end='\r')
print()

plot = dpc.Plot(
    transform=dpc.transforms.Grid(duration // 64, 1, 1),
    primitive=dpc.primitives.Line(),
)
for i, feature in enumerate(dlal.speech.FEATURES):
    plot.text(feature,
              **plot.transform(0, 0, None, plot.series),
              r=1.0,
              g=0,
              b=0)
    plot.plot([j[i] for j in features])
plot.show()
Beispiel #3
0

def random_color_for_position(x, y):
    r = random.randint(0, 255) % (x - 512 + 1)
    g = random.randint(0, 255) % (y - 768 + 1)
    b = random.randint(0, 255)
    a = random.randint(0, 255)
    return (r, g, b, a)


#===== general =====#
if args.case in ['1', 'general', 'all']:
    print(
        'plotting random dots, lines, text, in (x=512..767, y=768..1023), reddish on right, greenish on top'
    )
    plot = dpc.Plot('test')

    for i in range(10000):
        x, y = random_position()
        r, g, b, a = random_color_for_position(x, y)
        choice = random.choice(['point', 'line', 'text'])
        if choice == 'point':
            plot.point(x, y, r, g, b, a)
        elif choice == 'line':
            xf, yf = random_position()
            plot.line(x, y, xf, yf, r, g, b, a // 4)
        elif choice == 'text' and not random.randint(0, 100):
            s = ''.join(
                random.choice(string.ascii_letters + string.digits)
                for i in range(random.randint(1, 8)))
            plot.text(s, x, y, r, g, b, a)
 def __init__(self):
     self.plot = dpc.Plot()
     self.xy_prev = None
Beispiel #5
0
    4.48,
    4.58,
    4.65,
    4.84,
    4.88,
    4.99,
    5.05,
]

sample_rate = pe.audio.sample_rate()
run_size = pe.audio.run_size()
duration = pe.filea.duration()
samples = 0

if args.plot:
    plot = dpc.Plot()


#===== helpers =====#
def serialize_features(features):
    parts = ['{:02x}'.format(math.floor(i * 255)) for i in features]
    return ''.join([''.join(i) for i in zip(*parts)])


def bucketize(features):
    if features[0] < 0.3:
        return serialize_features(features[:5])
    else:
        return serialize_features((features[0], ) + features[5:])