Skip to content

Instantly share code, notes, and snippets.

@frivas
frivas / blinkingbkg.js
Created May 25, 2022 18:55
Chapter 06 - 6.2.3
function BlinkingBackground() {
const [isLeft, setLeft] = useState(true);
console.log(isLeft);
const onMouseMove = (evt) => {
return setLeft(evt.nativeEvent.offsetX < 90);
};
const divStyle = {
backgroundColor: isLeft ? "blue" : "red",
width: "100px",
height: "100px"
@frivas
frivas / hello_world_intent.py
Created May 2, 2019 16:56
HelloWorldIntent
def handle(self, handler_input):
# type: (HandlerInput) -> Response
polly = connectToPolly()
gender_detector = gender.Detector()
get_name = get_slot_value(handler_input, 'name')
logger.info(f"NAME {get_name}")
get_gender = gender_detector.get_gender(get_name.capitalize())
@frivas
frivas / launch_request.py
Created May 2, 2019 16:46
LaunchRequest
def handle(self, handler_input):
prepareTools()
polly = connectToPolly()
polly_mix_result = generatePollyMix(polly, "Hola, bienvenidos a esta skill de ejemplo. Prueba decirme nombres de chico y chica y eso determinará la voz que utilizaré", 'Lucia', background_file_intro)
audio_mix = getS3AudioFile()
speech_text = f"<speak> Esto es Poly {audio_mix} Dime un numbre</speak>"
@frivas
frivas / get_s3_audio_url.py
Created May 2, 2019 16:29
Get S3 Audio URL
def getS3AudioFile():
s3_filename = hashlib.md5(open('/tmp/output.mp3', 'rb').read()).hexdigest() + '.mp3'
s3.Bucket(bucket_name).upload_file(Filename='/tmp/output.mp3', Key=s3_filename, ExtraArgs={'ACL':'public-read'})
os.remove('/tmp/sound.mp3')
os.remove('/tmp/output.mp3')
return f'<audio src="{s3_url}{bucket_name}/{s3_filename}"/>'
@frivas
frivas / connect_to_polly.py
Created May 2, 2019 16:27
Connect to Polly
def connectToPolly(regionName=my_region, endpointUrl=polly_url):
return boto3.client('polly', region_name=regionName, endpoint_url=endpointUrl)
@frivas
frivas / prepare_tools.py
Created May 2, 2019 16:26
Prepare Tools
def prepareTools():
exists = os.path.isfile('/tmp/sox')
if not exists:
logger.info('FILE DOES NOT EXISTS')
cp_cmd_output = subprocess.run([f"cp {os.environ['LAMBDA_TASK_ROOT']}/audio/sox /tmp; chmod 755 /tmp/sox"], shell=True, stderr=subprocess.STDOUT, stdout=subprocess.PIPE)
logger.info(f"CP {cp_cmd_output}")
@frivas
frivas / variables.py
Created May 2, 2019 16:09
Setting up some variables
my_region = 'eu-west-1'
bucket_name = '<bucket_name>'
polly_url = f'https://polly.{my_region}.amazonaws.com/'
s3_url = f'https://s3-{my_region}.amazonaws.com/'
background_file_intro = f"{os.environ['LAMBDA_TASK_ROOT']}/audio/pavane_aws.mp3"
hello_file = f"{os.environ['LAMBDA_TASK_ROOT']}/audio/inspirational_aws.mp3"
@frivas
frivas / generatePollyMix.py
Last active May 2, 2019 16:08
Mixing Polly with Audip Clip
def generatePollyMix(polly, text, voice, backgroundSFX, format='mp3'):
resp = polly.synthesize_speech(OutputFormat=format, Text=text, VoiceId=voice)
soundfile = open(f"/tmp/sound.mp3", 'wb')
soundBytes = resp['AudioStream'].read()
soundfile.write(soundBytes)
soundfile.close()
audio = MP3("/tmp/sound.mp3")
audio_length = audio.info.length
@frivas
frivas / CloudFormation_APIGateway_EU_West_1.json
Last active December 15, 2021 15:15
CloudFormation_APIGateway_EU_West_1.json
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Deploy an HTTP Proxy API Gateway",
"Parameters": {
"AuthorizationURL": {
"Type": "String",
"Default": "<authorization_uri_from_alexa_dev_portal>",
"Description": "URI de Autorización de la sección Account Linking del Portal de Desarrollador de Alexa"
@frivas
frivas / index12.py
Created October 23, 2018 16:28
Import Random. Medium Article on Creating an Alexa Skill with Python
from random import sample