Search This Blog

Showing posts with label example. Show all posts
Showing posts with label example. Show all posts

Tuesday, December 10, 2019

Python Google Speech Setup and Example (WINDOWS)

1. Download SOX latest version - https://sourceforge.net/projects/sox/files/sox/

2. Install it (ex: C:\Program Files (x86)\sox-14-4-2 )
     2.1 download 2 (libmad-0.dll, libmp3lame-0.dll) DLLs and copy to C:\Program Files (x86)\sox-14-4-2;

                 https://app.box.com/s/tzn5ohyh90viedu3u90w2l2pmp2bl41t


3. Set environment path in system variable

4. Restart the IDE or CMD prompt

5. in cmd prompt
        set path=%path%;C:\Program Files (x86)\sox-14-4-2;
       echo %path%

6. pip install google_speech
    pip install sox

7. create a sample test.py


from google_speech import Speech

# say "Hello World"
text = "Hello This is Vijay DR";
lang = "en";
speech = Speech(text, lang);
speech.play();

# you can also apply audio effects while playing (using SoX)
# see http://sox.sourceforge.net/sox.html#EFFECTS for full effect documentation
sox_effects = ("speed", "1.5");
speech.play(sox_effects);

# save the speech to an MP3 file (no effect is applied)
speech.save("output.mp3");


8. cmp prompt py test.py



enjoy !
vijay

Thursday, July 18, 2019

Java RabbitMQ - Sample Send Receiver

//path lib setting
set CLASSPATH=.;lib\amqp-client-5.4.1.jar;lib\*.jar;lib\slf4j-api-1.7.26.jar;

//compile
javac TestSender.java

//run
java TestSender


TestSender.java

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

public class TestSender
{

private final static String QUEUE_NAME = "rmq";

public static void main ( String [] argv ) throws Exception
{
ConnectionFactory factory = new ConnectionFactory ();
factory.setHost ( "192.168.7.11" );
factory.setPort ( 8890 ); //always give HA port to test if you want to do HA testing. else give queue port
factory.setUsername ( "test" );
factory.setPassword ( "test" );
try (Connection connection = factory.newConnection ();
Channel channel = connection.createChannel ())
{
channel.queueDeclare (QUEUE_NAME, true, false, false, null );
String message = "Hello World111!";
channel.basicPublish ( "", QUEUE_NAME, null, message.getBytes ( "UTF-8" ) );
System.out.println ( " [x] Sent '" + message + "'" );
}
}
}


TestReceiver.java

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DeliverCallback;

public class TestReceiver
{

private final static String QUEUE_NAME = "rmq";

    public static void main(String[] argv) throws Exception {
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost ( "192.168.7.13" );
factory.setPort ( 5672 ); //always receive with your default queue port and not HA port
factory.setUsername ( "test" );
factory.setPassword ( "test" );

        Connection connection = factory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare(QUEUE_NAME, true, false, false, null);
        System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

        DeliverCallback deliverCallback = (consumerTag, delivery) -> {
            String message = new String(delivery.getBody(), "UTF-8");
            System.out.println(" [x] Received '" + message + "'");
        };
        channel.basicConsume(QUEUE_NAME, true, deliverCallback, consumerTag -> { });
    }
}



NOTE: channel.queueDeclare (QUEUE_NAME, true, false, false, null ); //if durable else give false instead of true.

Hit Counter


View My Stats