1. Trang chủ
  2. » Công Nghệ Thông Tin

Practical Arduino Cool Projects for Open Source Hardware- P18 doc

10 315 0
Tài liệu đã được kiểm tra trùng lặp

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 10
Dung lượng 204,77 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Shielded cable connected to female RCA line plug tted to an Arduino and plugged into an amplifier you can go to the following ding a small amplifier to the shield so you can drive a spea

Trang 1

Figure 9-7 Shielded cable connected to female RCA line plug

tted to an Arduino and plugged into an amplifier you can go to the following

ding a small amplifier to the shield so you can drive a speaker directly is quite easy with the LM386

io amplifier IC LM386 chips are very common in small audio devices, such as compact portable

radios, because they're very easy to use and produce reasonable quality sound at a good volume level

They certainly won't compete with the amp in your stereo system, but for simple voice-level output in a portable device they're perfect

Once your shield is fi

section “Speech Synthesizer Software” to test it out

On-Board Amplifier

Ad

aud

Figure 9-8 Pinout of LM386 audio amplifier

Trang 2

To build a simple audio amplifier with a gain of about 20 you can use the LM386 on

pretty much nothing else required However, with a few extra parts it can be configured

of about 50 If necessary it can be configured for a gain of up to 200, but that's pushing

it can do and since we're powering the amplifier circuit from the Arduino's 5V supply th

and noise on the supply rails could become a problem Audio amplifiers pull a lot more

typical digital circuits you might be used to dealing with on an Arduino: since amps equ

by volts, even a tiny 1/4W amplifier running on

its own with

to deliver a gain the limits of what

e current drain power than the als watts divided

a 5V supply can suck down 50mA of current, assuming it

uations

nt but rather jumps ble balance between a high output volume and low power consumption,

eed to use a

nd also make sure

d version of the output from the SpeakJet, so it uses the w-pass filter as the line-level output and then adds the LM386 to provide an amplified version of the signal Add the LM386 to the shield along with its associated parts, the 10K trimpot and the various resistors and capacitors, as shown in Figure 9-9 Finally, solder on the PCB-mount two-pin screw

terminal to provide a handy connection for a speaker

runs at an unrealistic 100% efficiency Even worse than the current drain, though, are the fluct

that can be induced on the supply rails, since the current consumption isn't consiste

around all over the place depending on the input signal

A gain of 50 gives a reasona

and won't strain the Arduino's power supply If you want more volume you'll probably n

more substantial external amplifier and feed it with the line-level output connection, a

the supply rails are adequately filtered

The LM386 needs to be fed with a filtere

same lo

Figure 9-9 Shield with LM386-based audio amplifier in place and speaker connected

If you have an old speaker from a stereo system you can connect a pair of wires to it and attach them

to the screw terminals Otherwise, use a small speaker from an electronics parts shop, an old computer

Trang 3

speaker, or even a speaker out of a car stereo system, and solder two wires to the speake

other ends into the screw terminals on the shie

r Then insert the

ld

Turn the trimpot to about halfway as a starting point so it has a reasonable volume level Mount the shield on your Arduino, and install the software to test it

ftware

phones to the ons at 9600bps we reSerial library, then specify which pins will be used for RX and TX We

t the SoftwareSerial RX (receive) pin, because all we'll be doing is sending values

to the SpeakJet and not reading anything back However, SoftwareSerial needs both to be defined so

we'll set it anyway and then ignore it

ftwareSerial.h>

s are stored as a series of allophones in an array, so to make it easier to read the array we'll

for the "Word Pause" value that is appended after each word The SpeakJet

s allophone 6

ly put WP into the alue

#define WP 6

e” to hold the allophones for the words we want to speak

d embedding comments within each line we can make the array much

lue onto the end of each word inserts allophone 6, the word pause

es it relatively simple to copy and paste different rds into place to make up your own sentences, as follows:

/* name */ 141, 154, 140, WP,

/* is */ 8, 129, 167, WP,

/* arduino */ 152, 148, 175, 147, 128, 141, 164, WP

};

Later the program will need to know the length of the message array, so rather than count the values manually and have to update it every time the message is changed we'll instead have the program count the array elements and store it for future reference

Speech Synthesizer So

To test the speech synthesizer, start with a minimal program that sends a series of allo

SpeakJet to sound out a simple sentence

Because the Arduino communicates with the SpeakJet using serial communicati

first need to include the Softwa

don't actually care abou

#include <So

#define rxPin 2

#define txPin 3

Then create a new software serial port object called "speakJet."

SoftwareSerial speakJet = SoftwareSerial(rxPin, txPin);

Word

define a memorable token

has six different pauses available, but the most commonly used pause between words i

which has a duration of 90 milliseconds By defining WP as the value 6 we can simp

word array as if it's a single byte, and not have to remember that allophone 6 is a magic v

Next, we'll set up an array called “messag

By breaking it up visually an

easier to read Finally, tacking a WP va

Working with the message array this way mak

wo

byte message[] = {

/* hello */ 183, 007, 159, 146, 164, WP, WP,

/* my */ 140, 155, WP,

Trang 4

int messageSize = sizeof(message);

The setup function is called once when the program starts, and configures the software serial

to the SpeakJet Since the SpeakJet runs by default at 9600bps we set up the software serial port to match

s a special case by

he volume) and 21 (which sets the speaking rate) When the SpeakJet sees either of these bytes it interprets the next byte as the value for that parameter and updates

se settings are stored in nonvolatile memory inside the SpeakJet

e to a value of 96 (on a scale of 0 through 127), we first send byte 20 (volume mmand) followed by a value of 96, as follows:

speakJet.print(20, BYTE);

TE);

Setting the speech rate is done in a similar way First we send byte 21 (speed command), followed by

speakJet.print(114, BYTE);

the setup function, olumes and speech rates The setup function then pauses for one second to give the SpeakJet time to receive and process the values

1000);

he main program loop is incredibly simple It steps through the message rray using a counter, i, and sends each value it finds to the SpeakJet via the serial connection defined

nds before repeating

void loop()

speakJet.print(message[i], BYTE);

}

delay (5000);

}

With a short sentence repeated at five second intervals there is plenty of time for the SpeakJet to say the whole the sentence before it is sent through again, so we are not checking for the Buffer Half Full state

connection

void setup()

{

pinMode(rxPin, INPUT);

pinMode(txPin, OUTPUT);

speakJet.begin(9600);

It then sends some initialization values to the SpeakJet Some bytes are treated a

the SpeakJet, including 20 (which sets t

its internal settings The

So, to set the volum

co

speakJet.print(96, BY

a value of 114 to set the speaking rate to 114 (on a scale of 0 to 127), as follows:

print( 21, BYTE);

speakJet

Both those settings are actually the default values, but by putting these lines into

it makes it easy to experiment with different v

delay(

}

After all that preparation t

a

earlier It then pauses for five seco

{

int i;

for (i=0; i<messageSize; i++)

{

Trang 5

When you power up your Arduino and speech synthesizer shield it will immediately say "ready,"

even if you haven't sent any values to the SpeakJet yet That's just the SpeakJet's internal self-test

indicating that it has finished and is ready to receive commands

nds listed below allow you to create any word you want your Arduino to say

hose sounds

mands and

nt to the SpeakJet Because the SpeakJet chip can also function as a multichannel sound synthesizer it has a number of commands other than the ones listed in

hat are relevant to speech synthesis are shown here Full details of all available omm ncluded in the SpeakJet datasheet

Table ommands

Byte Command

Create Your Own Messages

The allophones and comma

by breaking it up into sounds and then creating a list of the bytes that represent t

The SpeakJet accepts one-byte values from 0 to 255, with some values treated as com

others as allophones to sound out

Low values are used for commands se

Table 9-2 Just the ones t

c ands are i

9-2 SpeakJet c

Pause 3 (7

Pause 4 (30ms

Pause 5 (60ms)

Pause 6 (90ms)

0 Pause 0 (0ms)

1 Pause 1 (100ms)

2 Pause 2 (200ms)

7 Play next sound fast

8 Play next sound slow

14 Stress next phoneme

15 Relax next phoneme

20 Volume X (range 0–127, default 96)

21 Speed X (range 0–127, default 114)

22 Pitch X (range 0–255, default 88)

Trang 6

23 Bend X (range 0–15, default 5)

30 Delay X (range 0–255 times 10ms increments)

Five of the commands listed in Table 9-2 are two-byte commands The first byte sent i

command itself, and the second X byte is the value for that parameter Sending a pair

and then 56, would set the volume to a value of 56

Value

s the

of bytes, such as 20

s 128 and above are the allophones themselves Spoken sounds that are used to form words are values 128 through 199, and are listed in Table 9-3 with the letter representation of the associated

to show the pronunciation, the duration of the sound in milliseconds, and the type of sound

Spea

phoneme, sample words

Table 9-3 kJet allophones

128 IY See, Even, Feed 70 Voiced Long Vowel

130 EY Hair, Gate, Beige 70 Voiced Long Vowel

131 EH Met, Check, Red 70 Voiced Short Vowel

137 OW Comb, Over, Hold 70 Voiced Long Vowel

138 UH Book, Could, Should 70 Voiced Short Vowel

141 NE Nip, Danger, Thin 70 Voiced Nasal

Trang 7

143 NGE , Ping iced Nasal

146 LO Clock, Plus, Hello 70 Voiced Resonate

148 RR Ray, Brain, Over 70 Voiced Resonate

152 AWRR Part, Farm, Yarn 200 Voiced R Color Vowel

153 OWRR Corn, Four, Your 185 Voiced R Color Vowel

154 EYIY Gate, Ate, Ray 165 Voiced Diphthong

155 OHIY Mice, Fight, White 200 Voiced Diphthong

159 EHLL Saddle, Angle, Spell 140 Voiced Diphthong

161 AXUW Brown, Clown, Thousand 170 Voiced Diphthong

162 IHWW Two, New, Zoo 170 Voiced Diphthong

163 AYWW Our, Ouch, Owl 200 Voiced Diphthong

164 OWWW Go, Hello, Snow 131 Voiced Diphthong

165 JH Dodge, Jet, Savage 70 Voiced Affricate

Trang 8

166 VV t, Even iced Fictive

169 DH There, That, This 70 Voiced Fictive

170 BE Bear, Bird, Beed 45 Voiced Stop

171 BO Bone, Book, Brown 45 Voiced Stop

178 GE Get, Gate, Guest 55 Voiced Stop

182 CH Church, Feature, March 70 Voiceless Affricate

183 HE Help, Hand, Hair 70 Voiceless Fricative

184 HO Hoe, Hot, Hug 70 Voiceless Fricative

185 WH Who, Whale, White 70 Voiceless Fricative

186 FF Food, Effort, Off 70 Voiceless Fricative

187 SE See, Vest, Plus 40 Voiceless Fricative

Trang 9

189 SH iction, Leas less Fricative

192 TU To, Talk, Ten 70 Voiceless Stop

193 TS Parts, Costs, Robots 170 Voiceless Stop

194 KE Can't, Clown, Key 55 Voiceless Stop

197 OK Book, Took, October 45 Voiceless Stop

198 PE People, Computer 99 Voiceless Stop

Values 200 a spec ose s s such as sound effects and DTMF tones These are listed in Table 9-4

ab 4 SpeakJet sound effects and tones

nd above are ial purp ound

T le

Trang 10

209 R9 80 Ro

bot

Ngày đăng: 03/07/2014, 20:20

TỪ KHÓA LIÊN QUAN